0

I have a CollectionView the behavior is normal when I'm scrolling down and If I want to reach to top items using the scroll top top gesture from the status bar I get an extra space.

Extra space in title

Here is a gif showing the behavior:

I don't want that extra space.

I don't know if It's a property in the UICollectionView or in the same NavigationController.

Thanks!

Dennis Vash
  • 50,196
  • 9
  • 100
  • 118
Chila
  • 11
  • 1
  • 2
  • Have you pinned collectionView with Top, bottom, leading and trailing constraint? – Ahtazaz Apr 15 '19 at 17:46
  • I have my CollectionView with my four constraints align to safe area – Chila Apr 15 '19 at 18:08
  • Have you tried with self.automaticallyAdjustsScrollViewInsets = NO ?in ViewDidLoad ?? – Ahtazaz Apr 15 '19 at 18:15
  • Well my CollectionView is embedded in a ViewController and this ViewController embedded in a Navigation Controller and the Navigation Controller embedded in one of the tabs of a Tab bar controller: TabBar --> NavigationController --> ViewController --> CollectionViewController (as an element) I am using LargeTitles for the navigation bar. – Chila Apr 15 '19 at 18:17
  • "self.automaticallyAdjustsScrollViewInsets = NO" It did not work @Mr.Ahtazaz – Chila Apr 15 '19 at 18:19
  • Please take a look at this... i Hope this helps... https://stackoverflow.com/questions/43023384/uicollectionview-remove-top-padding – Ahtazaz Apr 15 '19 at 18:22
  • Let me know if it still not help you... – Ahtazaz Apr 15 '19 at 18:23
  • 1
    one of the solutions worked, the one to set the top constraint to the super view a not to the safe zone as I was doing, but I don't know why this behavior happens with the safe zone, thanks for the help @Mr.Ahtazaz – Chila Apr 16 '19 at 00:11
  • Sounds great... Good job... – Ahtazaz Apr 16 '19 at 02:56
  • I don't know why this Extra space is showing at your side. As it's strange. I have TEST same scenario(like Tab Bar Controller -> Navigational Controller -> View Controller(COLLECTION-VIEW as a subView of this View Controller HERE I'm not used COLLECTION-VIEW-CONTROLLER) And hook up the Collection-View Leading, Trailing, Top and Bottom constraint to SAFE AREA) But I didn't get any Extra Space on Top of the Collection View with/without Scrolling... – Ahtazaz Apr 16 '19 at 04:28
  • I have made a repo with an example in the storyboard I have two navigation for each case, the default is the one the stranger behavior, with the top constraint to the safe area and the second constraint to the super view if you have a time check it out! https://github.com/alexpcol/collectionView-scrollBug @Mr.Ahtazaz – Chila Apr 16 '19 at 15:23
  • Ok, let me check your Code... – Ahtazaz Apr 16 '19 at 16:23
  • Hi @Chila, Are you there? – Ahtazaz Apr 16 '19 at 16:41
  • yep here I am . – Chila Apr 16 '19 at 17:05
  • Brother i have just tried your code... and in both cases it works fine... Can yu come to Skype? – Ahtazaz Apr 16 '19 at 17:09
  • can't today, on Thursday would be great – Chila Apr 16 '19 at 17:26
  • ok np........... – Ahtazaz Apr 16 '19 at 17:27

2 Answers2

0

This worked for me the first method setting the top constraint to the superview an not to the safe area "Please take a look at this... i Hope this helps... uicollectionview remove top padding"

Thanks for your help Mr Ahtazaz

Chila
  • 11
  • 1
  • 2
0

you can try this, first drag and drop a view controller , then embed it into navigation controller, then drag and drop a collection view to the view controller select the collection view at the bottom there is "add new constraint" click on that and uncheck constraint to margin then give zero to all the four boxes and make sure the red line is highlighted( making sure all the constraints are sets) click on add constraint now you can rightclick and drag from tabbar to view controller and set it as viewcontrollers

Mohammad Yunus
  • 204
  • 1
  • 9