UIScrollView's contentOffset being reset when clicking anywhere

681 views Asked by At

I have an introduction sliding view pager type in my iOS app, and the last page has two text inputs. There are 7 pages being displayed in a scrollview that swipes left to right, so on the last page when the keyboard appears, I am having the contentOffset changed to push up the layout so the text inputs are still visible above the keyboard. Now anytime the user selects the next input, or even clicks really ANYWHERE on the page, the contentOffset is reset and the inputs are put back under the keyboard, which the user then needs to click out to reset the keyboard and click back on the 2nd input to enter their information. This is very counter intuitive and I need it to stop resetting.

Any ideas how I can achieve this? I have searched numerous things and no one ever has a clear answer on how to fix it even though I see many people have had the issue before... Thanks!

The code using

func keyboardWillShow(sender: NSNotification)
{
    if self.view.frame.height == 480.0
    {
        currentScrollViewOffset = CGPointMake(ContainerViewController.currentInstance.scrollView.contentOffset.x, ContainerViewController.currentInstance.scrollView.contentSize.height - (self.view.frame.height * 0.729))

        ContainerViewController.currentInstance.scrollView.setContentOffset(currentScrollViewOffset!, animated: false)        
    }
}

func keyboardWillHide(sender: NSNotification) {

    defaultScrollViewOffset = CGPointMake(ContainerViewController.currentInstance.scrollView.contentOffset.x, 0)

    ContainerViewController.currentInstance.scrollView.setContentOffset(defaultScrollViewOffset!, animated: true)
}

Please note that the ContainerViewController is the code handling and setting the different views into the one UIScrollView in the controller to have the swiping page introduction

Is there some way to capture the users "touch" and prevent the offset from being reset back to what appears to be (0,0)?

0

There are 0 answers