kharrison / CodeExamples

Code Examples
https://useyourloaf.com
BSD 3-Clause "New" or "Revised" License
2.13k stars 959 forks source link

Doesn't scroll #12

Closed m-montoya closed 4 years ago

m-montoya commented 4 years ago

Following this it doesn't scroll for me like the prior used to.

kharrison commented 4 years ago

Can you provide a bit more information of what you're doing?

m-montoya commented 4 years ago

Using the ScrollGuide on Xcode 11.0 (11A420a) on an iphone 7, can not set a dynamic height from code for the scrollview like used to be able to without everything recentering and scrolling not happening. Need to be able to change the scroll height for when the keyboard is shown so anything that sits behind the keyboard can be moved up.

kharrison commented 4 years ago

OK, so the problem is not with my sample code but something you are trying to do in your own code?

How are you creating your constraints? Can you post your code somewhere?

Typically to handle resizing of the scroll view to allow for the keyboard you would adjust the contentInset (see Unexpected keyboards for an example).

m-montoya commented 4 years ago

Prior to the new changes that came with 11, the old example you had worked very well with the being able to define a height for the scroll view. After the update and using the new example code given, defining a height for the scroll view as I was doing in the old example, things stopped working as they had. I already have some similar code to the link you posted for other areas app that were created prior to 11. Addition of a scroll view to a new area results in it not working.

The constraints are identical to the example. I then added a new height constraint to the scroll view. @IBOutlet weak var scrollViewHeightConstraint: NSLayoutConstraint!

Attempts to adjust this in the notification for keyboardWillShow or keyboardWillHide like so scrollViewHeightConstraint.constant = 900

The content would not scroll. If you haven't, you may try the new example code with a keyboard and the need to scroll up to view for example a textfield?

kharrison commented 4 years ago

I'm not seeing any problem when adjusting the scroll view contentInset which is how I would usually handle a keyboard.

How are you creating the height constraint? The scroll view in my example has its frame fully constrained to the root view, so adding an extra height constraint would not have any effect. Would be easier to help if you would post your code somewhere.

m-montoya commented 4 years ago

Sorry for the delay. Still can't get it to scroll. Unfortunately can't post code as there isn't any. All IB. So the scenario is like so

The constrains are identical to yours yet it won't scroll even though the content now stretches beyond the bottom of the phone. Did try removing the bottom constrain for the scrollview and setting a height for the scrollview but that didn't matter either.

kharrison commented 4 years ago

Post the entire Xcode project to a GitHub repo and drop the link here or email it to me. Without seeing how you are setting up the constraints it's hard to help more.

m-montoya commented 4 years ago

Here is the link to the repository https://github.tamu.edu/m-montoya/scrolltest Thx

kharrison commented 4 years ago

I don't seem to be able to access that link (needs a TAMU ID)

clumsyhamster commented 4 years ago

Oops. Sorry about that. Let's use the open 1. Try this https://github.com/clumsyhamster/scrolltest Thx

kharrison commented 4 years ago

You have a constraint from the bottom of the purple view to the bottom of the container view. You are missing a constraint from the bottom of the green view to the bottom of the container view.

If I remove the purple constraint and add the missing green view constraint it scrolls.

One tip, try using the view debugger and examine the height of the container view.

clumsyhamster commented 4 years ago

Thx for the quit update on the fix for fixed height views. I found that for dynamic content where the bottom containers height is not known and if you try to just set the bottom constraint to the container or no constraint at all, it'll complain about the scrollview needing a defined y position or height. Any ideas?

kharrison commented 4 years ago

What do you mean when you say that the bottom containers height is not known?

Either way the height of the content container view needs to be set based on the content and it needs to be fully constrained to the scroll view content layout guide.

m-montoya commented 4 years ago

Nevermind about this. Everything will generally have a defined height. I just need to figure out what that height will be and then define it. Appreciate all your help with this and thanks for your patience.