ios 如何阻止 UIWebView 在 phonegap 3.0 中垂直弹跳
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18799517/
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
How to stop UIWebView bouncing vertically in phonegap 3.0
提问by srvy
Have tried many suggestions from this and other forums, including setting "DisallowOverscroll" to "true". Is this broken in phonegap 3.0 by any chance ?
尝试了来自该论坛和其他论坛的许多建议,包括将“DisallowOverscroll”设置为“true”。这是否会在 phonegap 3.0 中被打破?
回答by Ashis Kumar
Make certain changes in config.xml
,
进行某些更改config.xml
,
If you are using it for Android, then use
如果您将其用于 Android,请使用
<preference name="disallowOverscroll" value="true" />
<preference name="webviewbounce" value="false" />
And for IOS, use like
对于 IOS,请使用类似
<preference name="DisallowOverscroll" value="true" />
<preference name="webviewbounce" value="false" />
Hope this helps you.
希望这对你有帮助。
EDIT
编辑
Do a cordova build
after you have made changes in the config.xml
file so that the changes affect to your project. The above steps would solve your problem only after you do a cordova build
cordova build
在config.xml
文件中进行更改后执行 a ,以便更改影响到您的项目。上述步骤只有在您执行以下操作后才能解决您的问题cordova build
回答by Vantoan8x
In the file AppDelegate.h, after initialized the MainViewController, you could disable this bouncing by set the scrollView class inside the webview by :
在文件 AppDelegate.h 中,初始化 MainViewController 后,您可以通过在 webview 中设置 scrollView 类来禁用此弹跳:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
....................
self.viewController.webView.scrollView.bounces = NO;
return YES;
}
The configuration value in the file config.xml was not used, I searched all in Cordova project.
config.xml文件中的配置值没有使用,我在Cordova项目中搜索了所有。
回答by Ally
For Cordova 3.x and above I believe you can set up your (void)webViewDidFinishLoad
in MainViewController.m
as follows :
对于科尔多瓦3.x和上面我相信你可以设置你(void)webViewDidFinishLoad
的MainViewController.m
,如下所示:
- (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];
}
Tested: Cordova 3.4, 3.5.
测试:Cordova 3.4、3.5。
回答by Соёмбо Бат-Эрдэнэ
this is method i've used in xcode way. i dont know how to solve that issue in phonegap maybe this few codes give you idea
这是我在 xcode 中使用的方法。我不知道如何在 phonegap 中解决该问题,也许这几个代码可以让您了解
in 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);
}
}
回答by Chris Lambrou
In your AppDelegate.m file , the "(UIApplication*)application didFinishLaunchingWithOptions.." section should look like this:
在您的 AppDelegate.m 文件中,“(UIApplication*)application 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 <content src='foo.html' /> 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;
}
Just add self.viewController.webView.scrollView.bounces = NO;before the return YES;
只需添加self.viewController.webView.scrollView.bounces = NO; 返回 YES之前;