Scroll View not behaving properly? - ios

I have a screen on which i am using scroll view.I am having scroll view as the parent view.
Scroll View constraints
center x to super view
leading space
trailing space
top space to top layout guide ,constant:-64.0
Inside scroll view i have a main view.
Man view constraints
center x to super view
leading space
trailing space
top space
bottom space,constant:-30
height:30
As you can see the image there is a label below but that label is not visible it is visible when i add the scroll the view.Please tell me how t fit the whole view into screen .Even on iPad it is not correct.

I don't think the issue is with scroll view . It's with your VC if you can check the size in size inspector it'll be at 0 below navigation bar.
you should just select your view controller open attribute inspector and deselct under Top Bars .
This will set your mainView which is embedded inside your VC to 64
and your scoll view should be at 0 Y. as you've alreday set your main view to 64.
Hope this helps :)

Related

Extra white space at bottom of UIScrollview

My Scroll View is pinned to the safe area on all 4 sides and is the size of the screen. I pinned the content view (view inside scroll view) to the content layout guide of the scroll view. And all my UI elements in the view are constrained properly so scroll view height ambiguity is not an issue. However the user can scroll down the continue button, and I don't know how to solve this issue.
This is the error I'm having:
Image for Extra space beneath content view inside scroll view
Another image. This causes white space beneath the blue view as so, I want the user to not be able to scroll past the blue view.
To make the button be fixed at the bottom of the view, then:
make sure the continue button and blue view are not inside the scroll view
constrain the blue view to the main view's bottom constraint
constrain the scroll view's bottom constraint to the top of the blue view
This way, the button will remain fixed, while the content within the scroll view will still be scrollable

Auto layout with navigation bar and container view

so, I'm pretty sure I have my auto layout constraints set up correctly... And I have my view controller embedded in a navigation controller. I put all of the things inside of a uiview that's constrained to the 4 sides of the phone (including the bottom of the navigation bar) but this is happening.
I have the picture constrained to the vertical center of the view, and at a 1:3 ratio to it's height. the buttons are constrained on the sides
the problem is that (as you can see by the button borders and the button text being off centered) everything seems to be larger than it should be and is causing an overlap, when the buttons are supposed to be flush against the bottom and top of the image view, but instead overflow on top of it (again, shown by the button borders)
ah, I'm just an idiot. Image View wasn't clipping subviews. Auto Layout's working just fine! Thanks. My b.

Gap between main view and scroll view using Auto Layout in navigation controller

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

How to make ScrollView width = to device screen width?

I am making an app that has a (child) View inside a Scroll View. I understand I have to explicitly set the child View's width since the Scroll View won't provide that information to the child, but how can I make this child View's width auto-adjust based on the width of the device?
For example, in the below I've set the width to 380 which centers the "Quotes" in iPhone 6, but makes them slightly right of center in iPhone 5.
You can use auto layout to set the width of your subView equal to your main View by performing a control drag from your subView to your main View like this:
Then select "Equal Widths" from the popup
Select viewController
Stretch the view you want full screen size to the size of the screen
Click the central icon from the three choices along the bottom of the window
You will an icon pop up
The top 4 values will have a dotted red line joining them
click them all
at the bottom of the pop up you will see 'add 4 constraints'
click this
Done!
You can delete the constraint for width. The view will place it self horizontally becuase of the leading and trailing space to superview. No need for a specific width.
I think your scrollview will be scrolling vertically so in that case you probably need to provide a constraint for the height or your view, and update scrollview contentsize accordingly to this.
Since your child view is located in the view hierarchy of your view controller's view you can assign constraints between your child view and your view controller's view.
Ctrl drag from your child view to your view controller's view. You will see option to set them to have equal widths. Select it. Then adjust the constant if you want the width of your child view to be lower.
You can then add leading and trailing constraints between your child view and your scroll view.
Doing it in this way will also ensure that you set the content width of you scroll view dynamically and correctly.
Let me know if it works for you

Auto layout: Pin top of view to bottom of another view programatically

I am switching my XIB file over to auto layout and have run into this problem I can't seem to find a good answer for on stack.
I'm looking to pin the top of one view to the bottom of another view programatically. Essentially, the top view pushes the bottom view downwards causing the height of the bottom view to be reduced proportionally while staying anchored at the bottom.
The top view is a fixed height while the bottom view is variable. In pseudo code, I essentially want this:
If the top view is present, pin the top portion of the bottom view, to the bottom of the top view while being anchored at the bottom (or reduce height to compensate for the top view)
Otherwise, the bottom view will be displayed at full height, essentially height = top view + reduced height bottom view
This needs to be done programmatically because the top view is only displayed conditionally, otherwise I want the bottom view to take up the height that would have been introduced by the top view.
Hope this makes sense!
If you had properties topView and bottomView of your self view, you could do this:
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:#"V:[_topView]-[_bottomView]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_topView, _bottomView)]];
Setting your top view's height to zero would answer your hiding question, too.

Resources