作者:国国国国涛 | 来源:互联网 | 2023-05-19 01:47
Ivedonelargeenoughresearchbutcouldntfindanswertomyquestion.我做了足够大的研究,但找不到我的问题的答案。Sup
I've done large enough research but couldn't find answer to my question.
我做了足够大的研究,但找不到我的问题的答案。
Suppose I have a webView
in which I have some text fields, some of them are placed on the bottom of screen so that when keyboard appears it should hide that fields. After keyboard appears the content of webView
slides up in order to make that fields visible. The problem is that I DON'T want the content to slide up.
假设我有一个webView,其中我有一些文本字段,其中一些放在屏幕的底部,这样当键盘出现时它应该隐藏那些字段。键盘出现后,webView的内容会向上滑动,以使这些字段可见。问题是我不希望内容向上滑动。
Question is: How can I disable that feature of webview
, or somehow make the content not scroll up.???
问题是:如何禁用webview的该功能,或以某种方式使内容不向上滚动。???
Thanks, any help would be appreciated.
谢谢,任何帮助将不胜感激。
3 个解决方案
17
If you want to disable ALL scrolling, including the auto-scroll when you navigate between form fields, setting webView.scrollView.scrollEnabled=NO
doesn't quite cover everything. That stops normal tap-and-drag scrolling, but not the automatic bring-field-into-view scrolling when you navigate around a web form.
如果要禁用所有滚动,包括在表单字段之间导航时自动滚动,则设置webView.scrollView.scrollEnabled = NO并不能完全覆盖所有内容。这样可以在浏览Web表单时停止正常的点击并拖动滚动,但不会停止自动带入场视图滚动。
Also, watching for UIKeyboardWillShowNotification
will let you prevent scrolling when the keyboard appears, but that will do nothing if the keyboard is already up from editing a different form field.
此外,观看UIKeyboardWillShowNotification将阻止您在键盘出现时滚动,但如果键盘已经编辑不同的表单字段,则无法执行任何操作。
Here's how to prevent ALL scrolling in three simple steps:
以下是如何通过三个简单步骤来防止所有滚动:
1) After you create the UIWebView, disable normal scrolling:
1)创建UIWebView后,禁用正常滚动:
myWebView.scrollView.scrollEnabled = NO;
2) Then register your view controller as the scrollView's delegate:
2)然后将视图控制器注册为scrollView的委托:
myWebView.scrollView.delegate = self;
(And make sure to add
to your class's @interface
definition to prevent compiler warnings)
(并确保将
添加到类的@interface定义以防止编译器警告)
3) Capture and undo all scroll events:
3)捕获和撤消所有滚动事件:
// UIScrollViewDelegate method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
scrollView.bounds = myWebView.bounds;
}