javascript - 当 native 键盘在移动设备上可见时禁用滚动

标签 javascript iphone html css keyboard

当用户单击输入字段或选择框并且 native iphone 键盘可见时,我的布局中断。我认为如果您可以在 native 键盘可见时禁用滚动可能是个好主意。 javascript 可以做到这一点吗?

提前致谢

最佳答案

您可以通过在 viewDidLoad 中注册接收关于 UIKeyboardDidShowNotificationUIKeyboardDidHideNotification 的通知来实现这一点

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

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

并按如下方式实现选择器

当键盘即将显示时,您会在此处接到电话

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

当键盘快要隐藏时你会在这里接到电话

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

很高兴我能看到这在某些方面对您有所帮助。快乐的一天。

关于javascript - 当 native 键盘在移动设备上可见时禁用滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11345400/

相关文章:

javascript - 是否可以根据徽章文本更改徽章颜色?

iphone - ? Xcode 中文件名后面的图标

iphone - 子类化 UIViewController 会导致内存问题吗?

javascript - Angular UI 路由器 : Setting autoscroll on header view does not scroll to top

javascript - 为什么这个正则表达式不起作用?

iphone - 向 MKMapView 添加 subview (不是叠加层)

Javascript 将数据保存到文件系统(带用户提示)

javascript - 从源代码中读取语言

html - 如何在 IE8 中垂直对齐文件输入的文件名

除非运行开发人员工具,否则 Javascript 无法运行