xcode 在 UIWebview 中停止滚动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9042456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Stop Scrolling in UIWebview
提问by TheChes44
I need to know how to stop scrolling in a UIwebview in xcode 4?
我需要知道如何在 xcode 4 的 UIwebview 中停止滚动?
[[[webView subviews] lastobject] setScrollingEnabled:NO];
The above code does not work because "NSarray" for instance message does not declare a method with selector 'lastobject'. Why is this or is there new code I am unaware of to disable scrolling? Thanks.
上面的代码不起作用,因为实例消息的“NSarray”没有声明带有选择器“lastobject”的方法。为什么会这样或者是否有我不知道禁用滚动的新代码?谢谢。
回答by DJPlayer
UIView* row = nil;
for(row in webView.subviews){
if([row isKindOfClass:[UIScrollView class] ]){
UIScrollView* scrollRow = (UIScrollView*) row;
scrollRow.scrollEnabled = NO;
scrollRow.bounces = NO;
scrollRow.backgroundColor=[UIColor clearColor];
}
}
your code is trying to make assumptions about the order of the subviews that Apple is defining..
您的代码试图对 Apple 定义的子视图的顺序做出假设。
回答by James Jones
Note that with iOS 5 you have direct access to the scroll view.
请注意,在 iOS 5 中,您可以直接访问滚动视图。
So if you wanted to maintain compatibility you could do this:
所以如果你想保持兼容性,你可以这样做:
UIScrollView *scrollView = nil;
if ([webView respondsToSelector:@selector(scrollView)]) { //iOS 5+
scrollView = webView.scrollView;
} else { //iOS 4-
for(UIView *view in webView.subviews){
if([view isKindOfClass:[UIScrollView class] ]){
scrollView = (UIScrollView *) view;
break;
}
}
}
scrollView.scrollEnabled = NO;
scrollView.bounces = NO;
scrollView.backgroundColor=[UIColor clearColor];
回答by Houtan
Simply add this line to viewDidLoad
:
只需将此行添加到viewDidLoad
:
myWebView.scrollView.scrollEnabled = NO;
回答by Damien
I would set the webview's UserInteractionEnabled
property to NO
so that it cannot be scrolled.
我会将 webview 的UserInteractionEnabled
属性设置为NO
使其无法滚动。