UIScrollView's contentOffset being reset when clicking anywhere

落花浮王杯 提交于 2019-12-12 04:53:36

问题


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)?

来源:https://stackoverflow.com/questions/27003775/uiscrollviews-contentoffset-being-reset-when-clicking-anywhere

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!