Why is View Controller scrolling above UIScrollView? - swift

Autolayout constraints not working properly with UIScrollView, allowing me to scroll above the scrollview even though the scrollview is constrained to the Super View, not the safe area.
Initial Load
Scroll Up
I've added a scrollview to a View Controller and constrained it to each edge of the super view, not the safe area. I've disabled "Adjust Scroll View Insets" in the View Controller as well as "Under Top Bars" and "Under Bottom Bars" within the "Extend Edges" block in the inspector. Everything in the storyboard appears to be correct. Also once I load the View Controller, everything also appears to be correct until I scroll up. I'm sure this relates to the Status Bar because it appears to be the exact height of it but I can't figure out what I'm supposed to adjust. This issue occurs on all devices including devices without notches.

The ScrollView's content inset adjustment behavior needed to be adjusted using scrollView.contentInsetAdjustmentBehavior = .never

Related

How can I make ScrollView full screen? I placed the necessary constraints, but it doesn't work

I'm trying to make a ScrollView so that its size adjusts to the size of the text. I placed all the necessary constraints
, but when the application is displayed on the simulator, the content view starts from the safe area and also ends up to the safe area. Although I have pinned scroll view to superview and content view to scroll view.
I want the content to start not from the safe area like here ,
but from the start of the screen like here
in other words, I want to remove the blue bar from the top and bottom
Do you have any ideas how to do it?
Sometimes UITableView & UIScrollView can still show safe area even though you attach your View to top of Super View. You just need to add one line to solve this issue but make sure your ScrollView is connected to superView not safe area at the top.
Add scrollView to your ViewController and in viewDidLoad() just write:
scrollView.ContentInsetAdjustmentBehavior = .never
Check this answer for further details: Make UITableView ignore Safe Area

Is it possible to scroll a Scroll View layered on top of a UITableView?

I have a child View Controller within a Container View that hosts a vertically-scrolling UITableView. Tapping a Button expands a separate View that covers the UITableView in the child View Controller. This new View contains a vertically-scrolling Scroll View. No matter what UITableView settings I change, I am unable to scroll the Scroll View unless I remove the UITableView entirely.
I am currently porting my fully-developed Android application to IOS, and my experience with Android Studio leads me to believe that this is an issue with the UITableView stealing focus from the Scroll View.
In short, how may I temporarily remove focus from the background UITableView to allow the overlaid Scroll View to scroll?
With Scroll Views up until this point, I have been setting the bottom -> Superview constraint to priority: 249 since I was having issues setting the contentSize. For some reason, having a Table View in the background disables this effect. My guess is that this happens because the Table View is forcing the Superview to anchor based on its own constraints, and therefore the Scroll View can no longer adjust based on low-priority constraints. Changing the Equal Height parameter of the Scroll View -> Superview to a proportional relation (x2) has temporarily addressed the problem.

How to add custom UIView to Stackview on top of UIScrollView programmatically?

I have a ViewController that has a UIScrollView with a vertical UIStackView on top of it.
Everything works fine if i add UIView to the stackview with height constraint trough the interface builder. For example 3 views with height 600px. If i run the app, i can scroll with no problem and see all three added views. The for the stackview works fine.
If i try to add a view to the stackview with code with addArrangedSubView trough code i can see that the first view that i added if i "force" scroll down, but not the other two. It doesnt matter if i set height constraints to the views that i add, and it doesnt matter if i set intrinsicContentSize for the custom views.
How can i get the scroll view to expand the scroll area when adding trough code. ?
Thanks :)
Just a guess in lack of more information:
The issue may be related to the way constraints are set up between the scroll view and its child, the stack view.
you should add the following constraints:
fix stack view edges (top, leading, trailing, bottom) to scroll view
set width constraint between stack view and scroll view
also set height constraint between stack view and scroll view, set its priority to low (250)
For more insights please read up on "setup UIStackView with auto layout", for example here:
https://medium.com/#pradeep_chauhan/how-to-configure-a-uiscrollview-with-auto-layout-in-interface-builder-218dcb4022d7
If it doesn't work please provide the relevant code and screenshots of your Interface Builder setup.

Can large titles be maintain when the user scrolls within a navigation controller

I've set navigationController?.navigationBar.prefersLargeTitles = true and I'm wondering is there any option that prevents the default action of scrolling the title into the main Navigation bar when the user scrolls.
I can't see anything obvious within the nav bar properties but wanted to ask first before I build my own view that I will pin to the bottom of the nav bar.
Thanks
Ok, I've solved my issue with a simple workaround that works great. Instead of adding my UIScrollView to the UIViewController.view and constraining it to the view.topAnchor, I've added a UIView [named staticView] to my UIViewController. Constraining that staticView to the view.topAnchor and then constraining UIScrollView to my static view prevents the largeTitles from being reduced, while still allowing the user to scroll.
When a UIScrollView is constrained to the topAnchor the OS reduces the nav bars large titles to their default size as the user scrolls. Having the scroll view pinned to the static view interrupts this behaviour and the large titles remain.

How to autosize view without auto layout in iOS

I have a problem that I can't understand resizing views. My deployment target is iOS 5.0, so I have disabled auto layout in the interface builder to make it compatible with iOS 5.0. The view does not resize automatically. Following is an example:
Interface Builder Snapshot:
4-inch screen:
3.5-inch screen (has problem):
As you can see, the button at the bottom of the view goes out of the screen. The background image also does not resize automatically. I can not understand how I can solve this problem. Can anyone help me?
Welcome to the pre-autolayout world! You must set the autoresizing "springs and struts" so that the stuff at the bottom is attached to the bottom of the superview and not the top. So, struts to the bottom, springs to the top. That way, as the superview gets larger and smaller, the stuff at the bottom moves with the bottom.
You could alternatively reposition the stuff in code, but there's no need in this situation.
Here's the section on autoresizing from my book:
http://www.apeth.com/iOSBook/ch14.html#_autoresizing
The part about the superview and the background image not being resized is a different matter. Is this the view of a UIViewController? If so, then if you are putting the UIViewController into the view controller parent-child hierarchy correctly, it will be resized by its parent. But you have not shown any code, so there's no telling what this view may be or how it is supposed to get into the interface.