【问题标题】:white space appear after call phonegap camera function调用phonegap相机功能后出现空白
【发布时间】:2014-03-10 01:25:20
【问题描述】:

在我的应用程序中,每当我调用相机(拍照或扫描条形码)时,底部都会添加一个空白(在 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});
}

};

可能的原因是什么?

【问题讨论】:

    标签: javascript ios cordova


    【解决方案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);
            }
        }
    }
    

    【讨论】:

    • 您好,看来这段代码不仅修复了gap问题,还修复了ios7中状态栏下的视图问题...
    • 那么,你的问题解决了吗?
    • 之前,我使用这段代码在状态栏下创建视图: // iOS7 解决状态栏下的视图 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { CGRect viewBounds = [self.webView 边界]; viewBounds.origin.y = 20; viewBounds.size.height = viewBounds.size.height - 20; self.webView.frame = viewBounds; }
    • 我认为这导致了这个问题......我删除了这段代码,只使用你发布的代码,差距问题消失了,状态栏也得到了修复
    • 你能解释一下这段代码的具体作用吗?我有兴趣
    【解决方案2】:

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

    【讨论】:

    • 问题是,调用这个摄像头的时候没有控制帧高,请问这个高度应该加到哪里?
    【解决方案3】:

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

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

    【讨论】:

      【解决方案4】:

      使用此代码

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-07-12
        • 1970-01-01
        • 2013-12-18
        • 1970-01-01
        相关资源
        最近更新 更多