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:
Related
I've added a TableView to my ViewController.
I have set the constraints like this:
Yet when i run the project the top of the firstcell(like 40px) is behind the NavigationBar:
What am i doing wrong here? Why is the TableView behind the navigationControllerBar?
Do not just set the constraint to 50, that's wrong on so many levels.
Constrain table view's top to top layout guide of view controller. This is gonna handle rotations for you as well. In landscape the navigation bar might have smaller height, this accounts for it as well. If you set it to 50 it's probably gonna look ridiculous.
Or pin the table view to the top of the superview as you do and set the contentInset property to the height of bars (this is useful if you wanna have translucent navigation bar and see the cells under navigation bar while you scroll). You can do this in code or storyboard:
You're not accounting for the navigation bar using the constraints. Set the top constraint to 50.
Since the scene in the Interface builder does not have a navigation bar - the constraints are not considering it and y (top) is set to 0 on the view, which does not have a navigation bar.
Either set the top constraint to 50 or put a bar in the view and set the top constraint to it.
In my app, I tried to use scroll view. But I encountered an issue where the scroll view added space at the top and bottom, as mentioned in the following question.
ScrollView adds space at the top of subview xcode 6 Swift
I was asked to uncheck "Adjust scroll view insets" of the containing view controller. Doing that solved my purpose.
But the scroll view isn't scrolling anymore. I'm not able to scroll to the views which are appearing at the bottom.
May I know what I need to do, to make it work ?. Thanks.
The way I solved the extra padding between the top label and the nav bar was by unchecking "Under Top Bars" in the attributes inspector, in the "Extended Edges" section. When you uncheck it, items on your storyboard may move around. Don't re-arrange them. Run simulator and it should work.
Note: leave "Adjust Scroll View Insets" checked, otherwise nothing scrolls.
My attributes:
I had exactly the same issue. This is how it worked for me. I added a screen shot of my object hierarchy
Leave Adjust Scroll View Insets checked.
Drag a view and place it in your Scroll View, cover the entire storyboard. This view will hold every UI object in your storyboard
Add top, right, bottom, left = 0 constraints from your Scroll view to Main View.
Add top, right, bottom, left = 0 constraints from your content view to Main View.
Add constraints from your UI object relative to your content view.
The imageView is placed under the navigation bar. Top, right, left constraints are set to 0 relative to content view. When I run the app my image appears right below the navigation bar.
Define in the viewDidLoad
self.automaticallyAdjustsScrollViewInsets = false
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
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'.
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'")