在iOS中使用Phonegap防止Webview被上下拖动
在使用PhoneGap制作App的时候,iOS作为承载App页面的容器的Webview,在手指向下或者向上滑动屏幕时,除了页面本身的滚动外,还经常会看到整体页面底部和屏幕底部被拖动出黑屏
为了防止这一滑动,可以通过修改修改项目中的MainViewController.m,重新设置WebView来实现
1 |
- ( void )webViewDidFinishLoad:(UIWebView*)theWebView |
2 |
{ |
3 |
// Black base color for background matches the native apps |
4 |
theWebView.backgroundColor = [UIColorblackColor]; |
5 |
|
6 |
[(UIScrollView *)[[theWebView subviews] objectAtIndex:0] setBounces:NO]; |
7 |
8 |
return [superwebViewDidFinishLoad:theWebView]; |
9 |
} |
在驿驴项目修改的地方是
- (void)webViewDidFinishLoad:(UIWebView*)webView
{
VerboseLog(@"webView didFinishLoad (before). state=%d loadCount=%d", _state, _loadCount);
BOOL fireCallback = NO;
// 禁止滚动上下滚动
[(UIScrollView *)[[webView subviews] objectAtIndex:0] setBounces:NO];
switch (_state) {
case STATE_IDLE:
break;
case STATE_WAITING_FOR_LOAD_START:
NSLog(@"CDVWebViewDelegate: Unexpected didFinish while waiting for load start.");
break;
case STATE_WAITING_FOR_LOAD_FINISH:
if (_loadCount == 1) {
fireCallback = YES;
_state = STATE_IDLE;
}
_loadCount -= 1;
break;
case STATE_IOS5_POLLING_FOR_LOAD_START:
[self pollForPageLoadStart:webView];
break;
case STATE_IOS5_POLLING_FOR_LOAD_FINISH:
[self pollForPageLoadFinish:webView];
break;
}
VerboseLog(@"webView didFinishLoad (after). state=%d loadCount=%d fireCallback=%d", _state, _loadCount, fireCallback);
if (fireCallback && [_delegate respondsToSelector:@selector(webViewDidFinishLoad:)]) {
[_delegate webViewDidFinishLoad:webView];
}
}
其实还可以这样
修改config.xml
<preference name="WebViewBounce" value="false" />
<preference name="DisallowOverscroll" value="true" />
posted on 2016-11-18 12:11 zhangzongshan 阅读(1138) 评论(0) 编辑 收藏 举报