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
Related
I have a save button that is supposed to be located right above the tab bar and right under the table view, but it does not appear in the view when I switch to a smaller screen. There is auto layout on all the elements, and the button is centered horizontally, equal width to the view, and has vertical spacing between the table view and bottom. Any ideas on how to make sure the save button always appears in the position stated above? Auto layout was done through storyboard not code.
set height of UIButton, and do not set height of UITableView.
I seem to be having issues when it comes to embedding a scrollview within a navigation controller. So here are the steps I take, and its really easy to replicate the weird error i seem to be getting.
1.) Drag and drop a UIViewController
2.) Followed by a UIScrollView
add constraints to UIScrollView, 0 on all sides, uncheck constrains to margins.
3.) Drag and drop another View into UIScrollView
add constraints to UIScrollView, 0 on all sides, uncheck constrains to margins.
Control drag from view into scroll view, make same width and height
After the following steps you will see in the following images that the view is not following the constraints I set, for some reason it thinks 0 is +64 from the top of scroll view? Not sure what I'm doing wrong here as it is very annoying visually.
In your view controller's attributes inspector, look for the Adjust Scroll View Insets and Extend Edges Under [Top|Bottom] Bar options.
I use view controller with embedded in navigation controller.
In this view I added scroll view and then content view inside scroll view
I added constrains for scroll view - zero for top, bottom, leading, and trailing. And the same for content view - zero for top, bottom, leading, and trailing.
And I added width and height for content view the same as main view.
Inside content view I need to add different content (labels, text fields, buttons) - this will be settings screen with vertical scroll.
Now I see that content is always shifted down a bit (the same value as menu height)
How to make to located vertically on top?
And how to put all the content in the content view that should be vertically long and scrollable vertically?
I think you forget to remove tick -> Adjust scrollview insects .
Just add this line to the viewDidload method of your ViewController.
self.automaticallyAdjustsScrollViewInsets = NO;
Check you attribute inspector setting in Storyboard.Uncheck
adjustScrollViewInsets
from viewcontroller storyboard.Viewcontroller Storyboard settings.
Go to storyboard and select the appropriate viewcontroller and Uncheck AutomaticallyadjustScrollviewInsets.
Or
Go to viewdidload
self.automaticallyAdjustsScrollViewInsets=NO;
Go to your viewcontroller viewDidLoad method put following code.
self.automaticallyAdjustsScrollViewInsets=NO;
In iOS 11, automaticallyAdjustsScrollViewInsets is deprecated and adjusting UIScrollView's contentInsetAdjustmentBehavior is recommended instead.
This worked for me pretty well (Swift):
scrollView.contentInsetAdjustmentBehavior = .automatic
I'm experiencing some trouble managing a scroll view embed inside a navigation view controller. I'm using Auto Layout and I'll try to explain the problem the best I can.
I embed a scroll view in the controller's main view and pinned the top, left, bottom and right borders to main view's borders.
I embed a standard UIView inside the scroll view and gave it a fixed height of 800 points. This should act as a container for all my controls (let's name it content view). Then again I pinned its top, left, bottom and right borders to the scroll view's borders. Because the bottom space constraint of scroll view's descendant view was negative, I adjusted it bringing it back to 0.
For the width, I CTRL-dragged from the content view to the main view and added a Equal widths constraint.
Finally, I added an image view and placed it at the top center of my content view adding some further trivial constraint.
The storyboard for the situation I've just depicted is shown above (in the document outline you should see all the constraints I've defined).
My scroll view works, it scrolls fine and the image view is well-centered where it's supposed to be. However, there's a gap between the end of the navigation bar and the start of the scroll view and I can't figure out why. It seems to be as high as the navigation bar, but I have no idea about how to fix it. The image shown below should make you understand what I'm talking about (the content view is highlighted in grey for clarity).
I didn't write a single line of code to achieve this result. I would really appreciate any kind of help and I'm ready to give you all the information you need to help me address the problem.
I think you should uncheck Adjust Scrollview Insets property of your viewcontroller to get rid of this....
you have to uncheck Adjust Scrollview Insets
I placed TableView on a middle of a layout with constraints to stay aligned with top/bottom guide bars and left/right sides.
When I insert prototype cell it doesn't go to the top and it's the same at run time. Seems like TableView holds space on top for something?
How do I make first cell to appear on top?
In your storyboard, adjust scroll view insets of your view controller is selected by default.
The best way to solve this problem is to add top and bottom constrains between the table view and its super view, instead of the layout guide, because the view controller will adjust the insects of the table view automatically.
By default, iOS adds a content inset on the UITableView. There are two solutions. You could either set the layout constraints to the top and bottom of the view instead of the top and bottom layout guides, or you could click on the view controller and in the attributes inspector, disable Extend Edges for Under Top Bars and Under Bottom Bars.