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

时间:2013-09-14 07:41:55

标签: ios cordova

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

5 个答案:

答案 0 :(得分:44)

config.xml

中进行某些更改

如果您将其用于Android,请使用

<preference name="disallowOverscroll" value="true" />

<preference name="webviewbounce" value="false" />

对于IOS,请使用

<preference name="DisallowOverscroll" value="true" />

<preference name="webviewbounce" value="false" />

希望这会对你有所帮助。

修改

cordova build文件中进行更改后执行config.xml,以便更改对您的项目产生影响。只有在执行cordova build

后,上述步骤才能解决您的问题

答案 1 :(得分:8)

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

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
    ....................

    self.viewController.webView.scrollView.bounces = NO;
    return YES;
}

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

答案 2 :(得分:1)

这是我用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);

}

答案 3 :(得分:1)

对于Cordova 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];
}

经测试:Cordova 3.4,3.5。

答案 4 :(得分:0)

在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 <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;
}

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