iOS UIcollectionview 数据量少时候bounces无效的解决方法
uiCollectionView在數據量很少時候。不足以填滿整個屏幕的時候bounces默認關閉。
解決方法
- (void)_edgeInsetsToFit {
UIEdgeInsets edgeInsets = self.collectionView.contentInset;
CGSize contentSize = self.collectionView.contentSize;
CGSize size = self.collectionView.bounds.size;
CGFloat heightOffset = (contentSize.height + edgeInsets.top) - size.height;
if (heightOffset < 0) {
edgeInsets.bottom = size.height - (contentSize.height + edgeInsets.top) + 1;
self.collectionView.contentInset = edgeInsets;
} else {
edgeInsets.bottom = 0;
self.collectionView.contentInset = edgeInsets;
}
}
然后在viewDidLayoutSubviews方法中。調用該方法
在給uicollectionView數據源賦值的時候。在刷新collection view之后。加入以下代碼
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{[self.view setNeedsLayout];});需要注意的是。本方法僅支持豎向滾動
總結
以上是生活随笔為你收集整理的iOS UIcollectionview 数据量少时候bounces无效的解决方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows 10 自动创建direc
- 下一篇: EditText禁止输入表情