繁体   English   中英

从PhoneGap Camera API返回时如何隐藏iOS7状态栏?

[英]How do I hide the iOS7 status bar when returning from PhoneGap Camera API?

我在使用Cordova / Phonegap构建适用于iOS7的应用程序时遇到了一个问题。 我无法很好地隐藏iOS7状态栏。

最初,我进入Xcode的plist并添加了所有正确的设置,以使状态栏不可见,就像在此解决方案中一样无法在iOS7中隐藏状态栏

在我使用Cordova CAMERA API遇到麻烦之前,这非常有用。 当我得到我的应用程序后,进入“相机胶卷”以选择图像(然后将其插入屏幕)。 选择图像并返回到应用程序后,状态栏再次可见。

我已经安装了状态栏cordova插件,并且试图将状态栏从相机设备返回到我的应用程序后立即将其隐藏。 惊喜-它不起作用! 但是,我可以启用一个按钮,该按钮调用一个函数以在单击时隐藏状态栏-但我希望它自动发生。

我在下面插入了我的代码:

<div id="Ccamera-fun" data-role="page" data-title="Camera Fun Activity">
  <div data-role="header" data-theme="e">
      <a href="#" data-rel="back" data-theme="h" data-icon="arrow-l" data-direction="reverse">Back</a>
      <h1>3.5 years - 4.5 years</h1>
  </div>
  <div data-role="content" data-theme="a" class="content">
   <h1>Camera Fun</h1>
   <div id="imageContainer"></div>
   <p>Use your photos and ask your child to describe one in detail. Use your photos as picture talks where your child can share their memories and recall events before or after the photo was taken. <strong>Together you could invent their own story.</strong></p>
    <p>Use the buttons below to take a picture with your phone or select an image from your phone&rsquo;s Photo Library. Once you have selected a photo, it will be embedded into the top of this screen.</p>
<script type="text/javascript" charset="utf-8">
    function hideStatus() {
     StatusBar.hide(); 
     navigator.notification.alert("status bar hidden");
    }

    function takePhoto() {
        navigator.camera.getPicture(onCameraSuccess,                            
        onCameraError,
        {quality: 50,
         destinationType : Camera.DestinationType.FILE_URI});
    }
    function onCameraSuccess(imageURL) {
        //HIDE STATUS BAR IMAGE
        StatusBar.hide();
        //GET A HANDLE TO THE IMAGE CONTAINER DIV
        ic = document.getElementById('imageContainer');
        //THEN WRITE AN IMAGE TAG OUT TO THE DIV USING THE URL WE RECEIVED FROM CAMERA APPLICATION
        ic.innerHTML = '<img src="' + imageURL + '" width="100%" />';
        navigator.notification.alert("onCameraSuccess:" + imageURL);
    }
    function onCameraError(e) {
        console.log(e);
        navigator.notification.alert("onCameraError:" + e);
    }
    function fromAlbum() {
        navigator.camera.getPicture(onLibrarySuccess,                            
        onLibraryError,
        {quality: 50,
         sourceType : Camera.PictureSourceType.PHOTOLIBRARY,
         allowEdit : true,
         destinationType : Camera.DestinationType.FILE_URI});
    }
    function onLibrarySuccess(imageURL) {
        //GET A HANDLE TO THE IMAGE CONTAINER DIV
        ic = document.getElementById('imageContainer');
        //THEN WRITE AN IMAGE TAG OUT TO THE DIV USING THE URL WE RECEIVED FROM CAMERA APPLICATION
        ic.innerHTML = '<img src="' + imageURL + '" width="100%" />';
        navigator.notification.alert("onCameraSuccess:" + imageURL);
    }
    function onLibraryError(e) {
        console.log(e);
        navigator.notification.alert("onCameraError:" + e);
    }
</script>
   <button onclick="takePhoto();" data-theme="h">Take a Picture</button>
   <button onclick="fromAlbum();" data-theme="h">Choose a Picture</button>
   <button onclick="hideStatus();" data-theme="h">Hide status bar</button>
 </p>
  </div>
</div>

如果有人能告诉我我要怎么做,我将不胜感激。

谢谢

这是一个phonegap错误,请参考CB-5265

您可以通过添加来解决此问题

 [[UIApplication sharedApplication] setStatusBarHidden:YES];

到位于CDVCamera.m中的imagePickerController:didFinishPickingMediaWithInfo:的末尾

但是,上面的代码对您来说只是一个快速修复,没有全面考虑它,您应该自己进行测试。

希望对您有所帮助!

Imnbeyond的解决方案对我不起作用。 我不得不进入我的清单,改变

View controller-based status bar appearance = YES

然后通过覆盖每个视图中的preferredStatusBarHidden方法来控制我的视图控制器中的状态栏,

-(BOOL)prefersStatusBarHidden{
    return YES;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM