我有一个屏幕上,我正在显示UICollectionView
.当我运行我的应用程序,它显示底部的空白空间,我不知道为什么会发生这种情况。我也添加了这段代码。
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
// return UIEdgeInsetsMake(0,8,0,8); // top, left, bottom, right
if (collectionView==self.album_collection_view)
{
return UIEdgeInsetsMake(0,10,0,10);
}// top, left, bottom, right
else
return UIEdgeInsetsMake(0,10,0,10);
}
但是这种方式不起作用。我也试过通过storyboard来解决这个问题,但它仍然不起作用。
在storybpard中,我已经尝试将section insect设置为所有方向的0
尝试将UIViewController的automaticallyAdjustsScrollViewInsets
属性设置为NO
。来自Apple文档:
讨论:该属性的默认值是
YES
,允许查看控制器来调整其滚动视图插入以响应屏幕状态栏、导航栏、工具栏或选项卡占用的区域酒吧。如果要管理滚动视图插入调整,请设置为NO
您自己,例如当视图中有多个滚动视图时层次结构。
设置为[self setAutomaticallyAdjustsScrollViewInsets:NO];
。然后设置集合视图的contentInset
属性以满足您的需要。
ok。但是看到你的代码,我不明白为什么你使用条件,如果你给相同的UIEdgeInsets在if和else。
希望这对你有帮助。
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionViewlayout:(UICollectionViewLayout*)collectionViewLayoutinsetForSectionAtIndex:(NSInteger)section{
if (collectionView == self.album_collection_view)
{
return UIEdgeInsetsMake(0,10,0,10);
}
else{
return UIEdgeInsetsMake(0,0,0,0);
}
}