Cordova / PhoneGap iOS:在拍照或打开InAppBrowser后,WebView变短了

时间:2014-08-07 13:18:19

标签: ios cordova webview

当我使用Camera插件拍照时,整个WebView变得更短。这就像屏幕从状态栏的高度从底部吃掉 - 20px。它根本不需要拍照,如果我只打开画廊然后关闭它,也会发生这种情况。如果我打开InAppBrowser然后关闭它,会发生同样的事情。这是一个例子:

This is how it looks before choosing a photo

这是选择照片之前的样子

Then the photo choosing dialog appears (doesn't matter if it's emulator, it behaves the same on the real device)

然后出现照片选择对话框(如果它是模拟器无关紧要,它在真实设备上的行为相同)

And then this happens when I close the dialog - look at the bottom of the screen

然后当我关闭对话框时会发生这种情况 - 请查看屏幕底部

And if I continue to add photos, each time the screen gets 'eaten' by 20px

如果我继续添加照片,每次屏幕被“吃掉”20px

我发现window.innerHeight减少了20px,所以它与状态栏有关。我怎样才能解决这个问题?

1 个答案:

答案 0 :(得分:0)

我在另一个帖子中偶然发现了答案。这是:

在MainViewController.h中:

@interface MainViewController : CDVViewController
@property (atomic) BOOL viewSizeChanged;
@end

在MainViewController.m中:

@implementation MainViewController

@synthesize viewSizeChanged;

[...]

- (id)init
{
    self = [super init];
    if (self) {
        // On init, size has not yet been changed
        self.viewSizeChanged = NO;
        // Uncomment to override the CDVCommandDelegateImpl used
        // _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self];
        // Uncomment to override the CDVCommandQueue used
        // _commandQueue = [[MainCommandQueue alloc] initWithViewController:self];
    }
    return self;
}

[...]

- (void)viewWillAppear:(BOOL)animated
{
    // View defaults to full size.  If you want to customize the view's size, or its subviews (e.g. webView),
    // you can do so here.
    // Lower screen 20px on ios 7 if not already done
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7 && !self.viewSizeChanged) {
        CGRect viewBounds = [self.webView bounds];
        viewBounds.origin.y = 20;
        viewBounds.size.height = viewBounds.size.height - 20;
        self.webView.frame = viewBounds;
        self.viewSizeChanged = YES;
    }
    [super viewWillAppear:animated];
}

来源:https://stackoverflow.com/a/19407903/1555838