aCertos aCertos - 4 years ago 193
Swift Question

TextViews not in correct position in ScrollView

I have two

boxes that are in a
which is in a
. My problem is that when I run the app in simulator, the
boxes are sitting lower than I would like, but after clicking within a
box, then dismissing the keyboard and my
function fires off, they set back to the position that I originally wanted them to be in. In my
function I did set the
content offset to go back to (0,0) so my initial solution thought is I need to set the content offset to (0,0) immediately which would then put both of my
boxes where I want them.

Now first I tried doing that in
, but there was no change, so I then tried setting it in
, which worked, but my issue with that is once the view appears, you actually see the textview boxes pop into place, and I do not like that. I also checked my constraints and they are all good, as i thought they might be causing the problem as well. I am not quite sure what I can do to make it work without actually seeing the
pop into place when the view appears.

This is what the
boxes look like when the view controller first comes up without the viewDidAppear method setting content offset.

enter image description here

And this is what I want the
boxes to look like.

enter image description here

Any help would be greatly appreciated. Thank you

Answer Source

In your viewDidLoad set viewController autoScollViewInsets to false:

override func viewDidLoad() {

    self.automaticallyAdjustsScrollViewInsets = false

you want more detail about this check this answer: Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download