Disable UIWebView default scrolling behavior using objective-c

允我心安 提交于 2019-12-01 02:43:53

问题


I know you can use a javascript to do this

<script type="text/javascript">
touchMove = function(event) {
event.preventDefault();
}

Is there a way to do the same using objective-c?


回答1:


try this...

UIView * v = [[webView subviews] lastObject];
[v setScrollEnabled:NO];
[v bounces:NO];

EDIT: Added checks to original answer based on comment below

UIView * v = [[webView subviews] lastObject];
if([v isKindOfClass:[UIScrollView class] ]) {
    if ([v respondsToSelector:@selector(setScrollEnabled]) {
        [v setScrollEnabled:NO];
    }
    if ([v respondsToSelector:@selector(bounces)]) {
        [v bounces:NO];
    }
}



回答2:


You can also access the scrollView like this :

webView.scrollView.scrollEnabled = false;
webView.scrollView.bounces = false;



回答3:


Using @aaron-saunders and @matt-rix 's answers, here's what works best for me :

UIView *v = [[webView subviews] lastObject];
if([v isKindOfClass:[UIScrollView class]])
    [v setScrollEnabled:NO];



回答4:


No need to use complex methods. You can access Scrollview of webview directly as below.

web_view.scrollView.scrollEnabled = NO;



来源:https://stackoverflow.com/questions/3800441/disable-uiwebview-default-scrolling-behavior-using-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!