简体   繁体   中英

UICollectionView scrollview has margin from top and bottom

Scroll indicators in UICollectionView starts after from some points from top and ends before that many points from bottom. I mean it has top and bottom margin from UICollectionView 's top and bottom.

Should not it start from top and end at bottom of UICollectionView ?

I checked that contentInset.top on UICollectionView and sectionInset.top on UICollectionViewFlowLayout are 20.0 and 0.0 , respectively.

See below image. Content start from more than 20.0 pts(which is top inset value) from top.

在此处输入图片说明

I solved by setting value of below properties to UIEdgeInsetsZero ,

// Set contentInset and scrollIndicatorInset to UIEdgeInsetsZero.
self.tournamentCollection.contentInset = UIEdgeInsetsZero;
self.tournamentCollection.scrollIndicatorInsets = UIEdgeInsetsZero;

Value of contentInset.top and scrollIndicatorInsets.top was 64.0 . Similarly for bottom . It was causing the contents to start 64.0 pts from top.

Note that you should check above properties' values only after layout pass is executed, otherwise you might get 0.0 as a value. This was the case with me. You should check in viewDidLayoutSubview: methods.

problem in translucent status bar and in your case also nav bar

if your collectionView starts right under nav bar when rendering to it added value to the top of the physical screen (64)

In its Projects I encountered a curious situation. A nav bar off translucency, but as soon as I hide it in one of the screens, then added to collectionView magic 20 pixels. Yes, yes, this is a translucent status bar had to take advice Geek

以@kolbasek的答案为基础,此其他问题的答案显示了如何在情节提要编辑器中对其进行更正(“ ...选择ViewController,然后取消选中'Adjust Scroll View Insets'”)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM