升級(jí)到了Xcode9之后 妓灌,出現(xiàn)了不少莫名奇妙的問題琅摩,之前可以的功能都突然不行了
項(xiàng)目中有用到UICollectionView厅各,collectionView數(shù)據(jù)無(wú)法加載出來(lái),如下2個(gè)方法均不執(zhí)行
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
經(jīng)過查證戈二,發(fā)現(xiàn)是這個(gè)collectionView是水平滑動(dòng)舒裤。重設(shè)了滑動(dòng)的方向,竟然導(dǎo)致上面2個(gè)方法不執(zhí)行
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
就是這個(gè)一句不起眼的代碼導(dǎo)致的>蹩浴L诠!
解決方法:在對(duì)應(yīng)的viewcontroller中加入
self.automaticallyAdjustsScrollViewInsets = NO;
然后就正常了·····好吧亏栈。你贏了
automaticallyAdjustsScrollViewInsets官方的解釋是
A Boolean value that indicates whether the view controller should automatically adjust its scroll view insets.
The default value of this property is YES, which lets container view controllers know that they should adjust the scroll view insets of this view controller’s view to account for screen areas consumed by a status bar, search bar, navigation bar, toolbar, or tab bar. Set this property to NO if your view controller implementation manages its own scroll view inset adjustments.
大致意思是:如果設(shè)置YES的話台腥,根據(jù)所在屏幕區(qū)域的status bar, search bar, navigation bar, toolbar, or tab bar.來(lái)調(diào)整scroll view的insets。
設(shè)置為NO的話绒北,自己修改布局黎侈,不要ViewController來(lái)控制。
查資料發(fā)現(xiàn)Xcode9之前就有這個(gè)問題闷游,所以并不是新版才出現(xiàn)的峻汉,至于為什么之前正常,現(xiàn)在不正常脐往。休吠。。