呼叫phonegap相机功能后出现空白区域

时间:2014-03-10 01:25:21

标签: javascript ios cordova

在我的应用程序中,每当我调用相机时(拍照或扫描条形码),底部都会添加一个空白区域(在ios 7上测试)。它可以增长我使用相机的次数。看起来像状态栏的高度相同。

相机只使用原生SDK,代码中没有别的东西。

CameraHelper.prototype.takeCameraImage = function(callback){
console.log("takeCameraImage");

navigator.camera.getPicture(onSuccess, onFail, {    quality: 49, 
                                                    destinationType: Camera.DestinationType.FILE_URI,
                                                    sourceType: navigator.camera.PictureSourceType.CAMERA,
                                                    correctOrientation: true,
                                                    targetWidth: 266,
                                                    targetHeight: 266
                                                });

function onSuccess(imageURI) {
    callback({imageURI: imageURI});
}
function onFail(message) {
    callback({message: message});
}

};

它的可能原因是什么?

enter image description here

4 个答案:

答案 0 :(得分:1)

尝试这个,将此代码放在MainViewController.m类

- (void)viewDidLayoutSubviews{

    if ([self respondsToSelector:@selector(topLayoutGuide)]) // iOS 7 or above
    {
        CGFloat top = self.topLayoutGuide.length;
        if(self.webView.frame.origin.y == 0){
            // We only want to do this once, or if the view has somehow been "restored" by other code.
            self.webView.frame = CGRectMake(self.webView.frame.origin.x, self.webView.frame.origin.y + top, self.webView.frame.size.width, self.webView.frame.size.height - top);
        }
    }
}

答案 1 :(得分:0)

对于高度尝试使用self.view.frame.size.height - 20(或状态栏高度)。

答案 2 :(得分:0)

我在OS 7.1上的iPhone上运行的cordorva应用程序上遇到了完全相同的问题。它也发生在对inAppBrowser的调用上。这里建议的解决方案都不适用于我。

然而,在MainViewController.m中找到它的工作是什么(从第78行开始):

- (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.
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
        CGRect viewBounds = [self.webView bounds];
        viewBounds.origin.y = 20;
        viewBounds.size.height = viewBounds.size.height - 20;
        self.webView.frame = viewBounds;
    }
    [super viewWillAppear:animated];
}

注释掉以下内容:

viewBounds.size.height = viewBounds.size.height - 20;

这完全解决了复合空白问题,我没有发现任何负面后果。

答案 3 :(得分:0)

使用此代码

 static int score = 0;
- (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.

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) {
    CGRect viewBounds = [self.webView bounds];
    viewBounds.origin.y = 10;
    //viewBounds.size.height = viewBounds.size.height - 18;
    if (score==0) {
        viewBounds.size.height = viewBounds.size.height - 18;
        score=1;
    }
    self.webView.frame = viewBounds;


}

[super viewWillAppear:animated];
}