简体   繁体   English

如何通过单击相机覆盖上的按钮打开照片库?

[英]How to open photo gallery by clicking a button from a camera overlay?

I'm working with Titanium SDK 3.1.2 and deploying for iOS and Android. 我正在使用Titanium SDK 3.1.2,并为iOS和Android进行部署。 You can find the code for my overlay HERE . 您可以在此处找到我的叠加层的代码。 I did this because the code is large and wanted my question to be clean and clear. 我这样做是因为代码很大,并且希望我的问题清晰明了。 I'm trying to create my own overlay for the camera with the following functions: Take a picture. 我正在尝试使用以下功能为相机创建自己的叠加层:拍照。 Show video camera. 显示摄像机。 Open gallery. 打开画廊。 Close camera. 关闭相机。 I'm able to close the camera and take a picture, but I'm unable to open the photo gallery. 我可以关闭相机并拍照,但无法打开照片库。 My galleryButton has a singletap event like this: 我的galleryButton有一个singletap事件,如下所示:

galleryButton.addEventListener("singletap", function(e){
        openKineduPhotoGallery();
        Ti.Media.hideCamera();
    });

But nothing happens when I do this and after that I'm not able to close the camera nor take a picture. 但是,当我这样做时什么也没有发生,之后我就无法关闭相机或拍照。 If I try to take a picture I get the following error: 如果我尝试拍照,则会出现以下错误:

Script Error {
        backtrace = "#0 () at file://localhost/var/mobile/Applications/79D9256C-7782-4323-A371-1AD45B37D037/Full.app/ui/common/GenericWindow.js:1\n#1 () at file://localhost/var/mobile/Applications/79D9256C-7782-4323-A371-1AD45B37D037/Full.app/ui/common/CreateMoment.js:1";
        line = 1;
        message = "'null' is not an object (evaluating 'o.type')";
        name = TypeError;
        sourceId = 81147840;
        sourceURL = "file://localhost/var/mobile/Applications/79D9256C-7782-4323-A371-1AD45B37D037/Full.app/ui/common/GenericWindow.js";
    }

I can't figure out what object is turning null for this to appear. 我无法弄清楚是什么对象使null出现。 I tried to swap the order in which I called the methods to make it look like this: 我尝试交换调用方法的顺序,使其看起来像这样:

galleryButton.addEventListener("singletap", function(e){
        Ti.Media.hideCamera();
        openKineduPhotoGallery();
    });

But that just hides the camera and doesn't show the gallery at all, plus I get the following warning in iOS: 但这只是隐藏了相机,根本没有显示图库,而且我在iOS中收到以下警告:

Nov  6 18:37:20 Nenvo-iPod Full[3240] <Warning>: *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit/UIKit-2380.17/UIWindowController.m:211
Nov  6 18:37:20 Nenvo-iPod Full[3240] <Warning>: Warning: Attempt to dismiss from view controller <UIImagePickerController: 0x1e5e17a0> while a presentation or dismiss is in progress!

I thought it was the hideCamera method fault so I commented that but that just triggers the error function on the showCamera method and I get a JSON error object like this: 我以为这是hideCamera方法的错误,所以我对此进行了评论,但这只是触发了showCamera方法上的错误函数,并且我得到了这样的JSON错误对象:

{
  "type": "error",
  "code": 1,
  "source": [object MediaModule],
  "success": false
}

I tried to stringify MediaModule but it just returned an empty object. 我试图对MediaModule进行字符串化,但它只是返回了一个空对象。 Is it even possible to open the gallery from a camera overlay? 甚至有可能从摄影机叠加层打开图库吗? What are my options? 我有什么选择? I'm trying to achieve a workflow similar to how instagram takes pictures, records video and selects a picture from gallery. 我正在尝试实现类似于instagram拍照,录制视频并从画廊中选择图片的工作流程。

to answer for below problem is actually when you call hideCamera and open PhotoGallery then both are opened as modal window so we need to call openKineduPhotoGallery function after friction of seconds. 回答以下问题的方法实际上是当您调用hideCamera并打开PhotoGallery,然后将两者都打开为模态窗口,因此我们需要在几秒钟的摩擦后调用openKineduPhotoGallery函数。

galleryButton.addEventListener("singletap", function(e){
        Ti.Media.hideCamera();
        openKineduPhotoGallery();
});

so you should try the below code. 因此,您应该尝试以下代码。

   galleryButton.addEventListener("singletap", function(e){
            Ti.Media.hideCamera();
            setTimeout(function(){
                    openKineduPhotoGallery();                   
            },500);
    });

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

相关问题 如何从相机拍摄照片并在Android应用程序中添加照片库? - How to take photo from camera and add photo gallery in android application? 如何recyclerview适配器imageview选择打开相机获取图像并从照片库中选择一张图片? - how to recyclerview adapter imageview select open camera get image and choose a picture from the photo gallery? 如何在意图打开的相机中添加图库按钮? - How to add gallery button to Camera open with intent? 从相机和画廊获取照片 - Getting photo from camera and gallery 如何调整相机或画廊照片的大小 - How to resize camera or gallery photo 从图库/相机中选择照片InAppBrowser - Select a photo from gallery/camera InAppBrowser Turbolinks-如何在表单按钮上打开本机摄像头/图库 - Turbolinks - How to open native camera/gallery on form button click 使用Phonegap / Cordova相机插件从相机或图库中选择照片 - Using the Phonegap/Cordova camera plugin select photo from camera OR gallery 如何从app小部件打开相机和图库的Intent选择器 - How to open the Intent chooser for camera and gallery from app widget 如何打开Android照片库中的特定图像? - how to open a specific image in the android photo gallery ?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM