简体   繁体   中英

Disable scrolling when native keyboard is visiable on mobile

My layout breaks when the user clicks a input field or a selectbox and the native iphone keyboard gets visible. I thought it might be a good idea if you could disable scroll when the native keyboard is visible. Could javascript achieve that?

Thanks in advance

You can achieve this by register for recieving the notifications on UIKeyboardDidShowNotification and UIKeyboardDidHideNotification in the viewDidLoad

[[NSNotificationCenter defaultCenter] addObserver: self 
                                         selector: @selector(keyboardWasShown)
                                             name: UIKeyboardDidShowNotification
                                           object: nil];

[[NSNotificationCenter defaultCenter] addObserver: self
                                         selector: @selector(keyboardWasHidden)
                                             name: UIKeyboardDidHideNotification 
                                           object: nil];

And implement the selectors as below

When the keyboard is about to show you will get a call in this

- (void) keyboardWasShown
{
   // Code to disable the scrolling of your scrollview
}

And when the keyboard is about to hide you will get a call here

- (void) keyboardWasHidden
{
    // Code to enable the scrolling of your scrollview
}

Glad if i can see this helps you in someways. Happy day.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM