[問題] UICollectionView的UIView animate問題

看板MacDev作者 (阿璋仔)時間9年前 (2014/12/13 12:55), 9年前編輯推噓0(004)
留言4則, 2人參與, 最新討論串1/1
大家好 大概的架構是在UITableView上面貼了兩個CollectionView 我原本用下列這種方式,CollectionView是可以正確的改變大小 [UIView animateWithDuration:0.2 delay:0.1 options:UIViewAnimationOptionCurveEaseIn animations:^{ CollectionView.frame = CGrectRectMake = (0,0,300,300); } completion:^(BOOL finished) { menu_status =1; } ]; 但自從我在ViewDidLoad加了dispatch_async後 上面的程式碼就無法跑出原本的效果,畫面中frame大小並未改變 但我用NSLog在動畫前跟後印出frame大小,數值是有改變的 請大大們指點要怎麼修改?謝謝 附上dispatch_async部分代碼 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // 抓取Json資料 NSArray * itemParser = [self jsonDataParserArray:WebUrl]; dispatch_async(dispatch_get_main_queue(), ^{ //將Json資料加到Array裡面以後reloadData顯示畫面 firstDictionary = [[NSMutableDictionary alloc]init]; FileName = [[photoArray objectAtIndex:photoIndex] objectForKey:@"iconFile"]; [firstDictionary setObject:FileName forKey:@"image"]; [Tableview reloadData]; }); }); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 42.71.209.227 ※ 文章網址: http://www.ptt.cc/bbs/MacDev/M.1418446552.A.FB7.html ※ 編輯: chengpocheng (42.71.209.227), 12/13/2014 13:00:24 ※ 編輯: chengpocheng (42.71.209.227), 12/13/2014 13:02:16

12/13 13:48, , 1F
dispatch_get_main_queue UI操作要在mainthread下
12/13 13:48, 1F

12/13 15:58, , 2F
謝謝S大給我的靈感,問題解決了
12/13 15:58, 2F

12/13 16:03, , 3F
由於在抓JSON資料時會先創造UICollectionView一次
12/13 16:03, 3F

12/13 16:10, , 4F
在CellAtIndex加個陣列數不為0的判斷式就解決了3Q
12/13 16:10, 4F
文章代碼(AID): #1KYyRO-t (MacDev)