如何阻止UIWebView在phonegap 3.0中垂直弹跳

已尝试过此论坛和其他论坛的许多建议,包括将“DisallowOverscroll”设置为“true”。 这有可能在phonegap 3.0中被打破吗?

config.xml某些更改,

如果您使用的是Android,请使用

   

对于IOS,请使用

   

希望这对你有所帮助。

编辑

config.xml文件中进行更改后执行cordova build ,以便更改对项目产生影响。 只有在进行了cordova build之后,上述步骤才能解决您的问题

在AppDelegate.h文件中,在初始化MainViewController之后,您可以通过在webview中设置scrollView类来禁用此弹跳:

 - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { .................... self.viewController.webView.scrollView.bounces = NO; return YES; } 

没有使用文件config.xml中的配置值,我在Cordova项目中搜索了所有内容。

这是我用xcode方式的方法。 我不知道如何在phonegap中解决这个问题,也许这几个代码可以让你有所了解

在viewdidload中:

 webView.scrollView.delegate = self; [webView.scrollView setShowsHorizontalScrollIndicator:NO]; -(void)scrollViewDidScroll:(UIScrollView *)scrollView 

{

 if (scrollView.contentOffset.x > 0 || scrollView.contentOffset.x < 0 ) scrollView.contentOffset = CGPointMake(scrollView.contentOffset.y, 0); 

}

对于Cordova 3.x及更高版本,我相信您可以在MainViewController.m设置(void)webViewDidFinishLoad ,如下所示:

 - (void)webViewDidFinishLoad:(UIWebView*)theWebView { // Black base color for background matches the native apps theWebView.backgroundColor = [UIColor blackColor]; theWebView.scrollView.bounces = NO; return [super webViewDidFinishLoad:theWebView]; } 

经测试:cordova3.4,3.5。

在您的AppDelegate.m文件中,“(UIApplication *)应用程序didFinishLaunchingWithOptions ..”部分应如下所示:

 /** * This is main kick off after the app inits, the views and Settings are setup here. (preferred - iOS4 and up) */ - (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { CGRect screenBounds = [[UIScreen mainScreen] bounds]; #if __has_feature(objc_arc) self.window = [[UIWindow alloc] initWithFrame:screenBounds]; #else self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease]; #endif self.window.autoresizesSubviews = YES; #if __has_feature(objc_arc) self.viewController = [[MainViewController alloc] init]; #else self.viewController = [[[MainViewController alloc] init] autorelease]; #endif // Set your app's start page by setting the  tag in config.xml. // If necessary, uncomment the line below to override it. // self.viewController.startPage = @"index.html"; // NOTE: To customize the view's frame size (which defaults to full screen), override // [self.viewController viewWillAppear:] in your view controller. self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible]; self.viewController.webView.scrollView.bounces = NO; return YES; } 

只需添加self.viewController.webView.scrollView.bounces = NO;返回之前;