当 UIScrollview 作为子视图存在时,UIWebview scrollsToTop 不起作用
我在 UIWebView 上遇到 setScrollsToTop:
问题。 webview 是根视图控制器的子视图,在 viewDidLoad 上我设置:
[self.webView.scrollView setScrollsToTop:YES];
但是,当我点击状态栏时,webview 将不会滚动到顶部。在应用程序内的另一个模态 tableViewController 上,它工作正常,甚至无需设置 setScrollsToTop:YES 。这是应用程序委托内 applicationDidFinishLaunching
中的代码:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.f = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
self.window.rootViewController = self.f;
[self.window makeKeyAndVisible];
return YES;
如何使其工作?
编辑:似乎同一视图中的 UIScrollview 导致了问题。我怎样才能让它与 UIScrollView 一起工作?
I'm having an issue with setScrollsToTop:
on UIWebView. the webview is a subview of the root view controller and on viewDidLoad
I set:
[self.webView.scrollView setScrollsToTop:YES];
However when I then tap the status bar the webview won't scroll to the top. On another modal tableViewController inside the app it works fine, without even setting setScrollsToTop:YES
. This is the code in applicationDidFinishLaunching
inside the app delegate:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.f = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
self.window.rootViewController = self.f;
[self.window makeKeyAndVisible];
return YES;
How can I make it work?
EDIT: It seems like a UIScrollview that is in the same view is causing the problem. How can I make it work with the UIScrollView?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试在 UIScrollView 上设置
setScrollsToTop:NO
。根据 关于 setScrollsToTop 的文档:在 UIScrollView 中,
Try setting
setScrollsToTop:NO
on the UIScrollView.According to the docs on setScrollsToTop: in UIScrollView,
使用这里的答案:UIScrollView + UIWebView = NOscrollsToTop
对我来说就像一个魅力。
我有一个嵌入了 UIWebView 的 UIScrollView 。
use the answer here: UIScrollView + UIWebView = NO scrollsToTop
worked for me like a charm.
i had a UIScrollView with a UIWebView embedded.
如果我遇到问题,也许这些代码可以解决您的问题。
有时 self.automaticallyAdjestsScrollViewInsets 无法正常工作。所以,只需将其关闭即可。
Maybe those code will solve you problem if I get the problem.
Sometime the self.automaticallyAdjestsScrollViewInsets is not wokring as usual. So, just turn off it.