the item height must be less than the height of 導航下scrollview產生偏移的問題


最近用UICollectionView寫了一個卡片輪播,ios12上效果完美,在ios10上跑了一下發現視圖出現偏移,效果如下圖

找了好久原因最后發現在ios10上控制台打印了如下提示內容

 The behavior of the UICollectionViewFlowLayout is not defined because:
 the item height must be less than the height of the UICollectionView minus the section insets top and bottom values, minus the content insets top and bottom values.
 The relevant UICollectionViewFlowLayout instance is <CollectionFlowLayout: 0x7f83d7d5d230>, and it is attached to <UICollectionView: 0x7f83d8111000; frame = (0 0; 375 160); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x600000058ba0>; layer = <CALayer: 0x600000221460>; contentOffset: {0, 0}; contentSize: {126, 111}> collection view layout: <CollectionFlowLayout: 0x7f83d7d5d230>.
 Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.

上網查了下原因發現在ios11以下系統中導航控制器下當self.automaticallyAdjustsScrollViewInsets = YES;時,控制器下的scrollview的contentInset會默認向下偏移64,所以把這個屬性設為NO就可以了,希望對遇到同樣問題的朋友有幫助


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM