UICollectionView scrollview has margin from top and bottom - ios

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

Building on #kolbasek's answer, this other question's answer shows how to correct it in Storyboard editor ("...select the ViewController, and then untick 'Adjust Scroll View Insets'")

Related

Issue with UIScrollView and parallax effect

I am trying to replicate something similar to Android's collapsing toolbar (see this link to understand the effect I am trying to achieve). I found a nice turnaround here.
My main UIScrollView is named fgScrollView and the secondary which is pinned on top is named bgScrollView. The whole UIViewController is embedded in a UINavigationController.
I pin the fgScrollView to the Container View. I pin the bgScrollView top, right and left to the fgScrollView and I give it a steady height of 220, and I place inside the bgScrollView a UIImageView which I also pin to all sides and I give it a height of 220. (All pins are with 0 distance)
This is how it looks from the IB (the UILabel that you see in the hierarchy is placed there to give a scrollable height to the fgScrollView):
In the scrollViewDidScroll method I set:
bgScrollView.contentOffset.y = scrollView.contentOffset.y * 1.4
(I have already set only the fgScrollView to be the delegate and I chose the 1.4 randomly) and in Interface Builder I choose the Adjust Scroll View Insets option.
The result is this in the beginning:
but as soon as I click to scroll up this happens (you can see the gap - it stops being pinned to the top):
From thereon it stays like that when I scroll to the top.
I uncheck the Adjust Scroll View Insets option and a strange thing that I notice is that the image does not go under the navigation bar, although I have checked the options Under Top and Bottom Bars:
And when I start scrolling this happens:
and it stays like that even when I scroll back to the top.
I tried to fix the issue programmatically. I add the navigation bar and status bar heights and I declare this:
fgScrollView.contentInset = UIEdgeInsets(top: CGRectGetHeight((self.navigationController?.navigationBar.frame)!) + CGRectGetHeight(UIApplication.sharedApplication().statusBarFrame), left: 0,
bottom: CGRectGetHeight((self.navigationController?.toolbar.frame)!), right: 0)
and the result is this:
Any clues?...

iOS 8 after hiding tab bar - reuse this space to display a text box

I can hide the tab bar programmatically. The view underneath is a scrollview displaying content. When I scroll up/down I can see the white space at the bottom where the tab bar used to be. My content is not able to use that space.
I want to display a text box in that white space along with some buttons. Any suggestions on how can I do that?
Solution:
Thanks to "SwiftArchitect" advice. I was able to fix this by adding bottom constraints for the ScrollView. Now the scrollview goes till the bottom of the screen.
As often is the case with AutoLayout, this question becomes trivial when using Storyboard and either the ViewLayoutAssistant or an image which will show evidence of resizing.
Let's assume that you are adding 4 constraints for your scroll view:
vertical space view.top (0) equal to Top Layout Guide.bottom
vertical space view.bottom (0) equal to Bottom Layout Guide.top
and 4. horizontal leading and trailing space
...then when hiding the tabBar:
if let tabBarController = self.tabBarController {
tabBarController.tabBar.hidden = true
}
the view.bottom, anchored to the Bottom Layout Guide.top, will now stretch all the way to the bottom. If you add a UILabel above that line, it will show.
Here is what it would look like in the Storyboard:
When executed with the ViewLayoutAssistant, the UIViewController that hides the navBar as follow will look like this (notice that the view now stretches all the way to the bottom since the Bottom.Layout.Guide moved down):

How to fit tableview to superview below navigation bar via storyboard autolayout

I want to create a scroll disabled tableview which will fill the view below navigation bar. Finally I've managed to do it but it's not the right way because I'm giving minus 64 margin (status bar + navigation bar) to tableview.
I'm assigning my constraints from storyboard. I've tried lots of other constraints with the table view like giving zero constraints from 4 sides or
equal width + equal height + center horizontal + center vertical none of them worked.
What is the right way to solve this problem.
Screenshot from the storyboard are below.
I solved it.
unchecking four of them and adding the constraints from image below worked as I wanted.
So I guess scroll disabled tableviews not working as expected with these four view controller options checked.
As kerem keskin said, unchecking resolves the issue but you don't need to uncheck all four. Just need to uncheck Adjust Scroll View Inset.
Refer to this: iOS 7 -- navigationController is setting the contentInset and ContentOffset of my UIScrollView

Unexplained margin in Auto Layout

Pretty simple really. I've got a yellow scrollView that contains a blue view. In the xib, I've set the blue view to totally fill its parent (the scrollView), by matching all their borders with 0 offset:
And yet, here it is at execution:
At this point, I've stripped down the code to its strict minimum to isolate the cause of the error, and I'm left with nothing left in my code. I tried setting translatesAutoresizingMaskIntoConstraints to NO and calling layoutIfNeeded for all views, it doesn't change anything. Do you guys have any idea where this space on the top comes from?
The contentInset is affected by the (height of the) navigation bar.
Try setting self.automaticallyAdjustsScrollViewInsets = NO;
This can also be set in the storyboard with 'Adjust Scroll View Insets'.

Remove unwanted ios7 padding

iOS7 adds padding (64px) for the status bar. Therefore when using a Scrollview there is a big camp between the scrollview and the navigation bar. I tried:
self.automaticallyAdjustsScrollViewInsets = NO;
Which does remove the unwanted padding - however the scrollview no longer scrolls.
Is there another way?
* update **
I discovered a quick fix. I was lining up the scrollview and y origin= 64px in the storyboard instead of 0. I put my scroll view to 0px (the navigation bar then covered 64px of my scrollview) and when I ran it on the simulator it was aligned as originally intend ... a bit of a hack tho. I'm looking for a solid solution however.
On your XIB/Storyboard for your view controller, make sure to uncheck the Adjust Scroll View Insets. You may also need to uncheck Under Top Bars and Under Bottom Bars:

Resources