【问题标题】:UIImagePickerController: ignoring request to take picture; camera is changing modesUIImagePickerController:忽略拍照请求;相机正在改变模式
【发布时间】:2013-11-05 17:03:55
【问题描述】:

这个错误是在 ios7 上抛出的,我在 Titanium 中构建了一个小示例相机应用程序,代码如下:

index.js

var overlay = Ti.UI.createView({
    width: Ti.UI.FILL,
    height: Ti.UI.FILL,
    backgroundColor: 'transparent'
});

var takePhotoBtn = Ti.UI.createButton({
    width: '200dp',
    height: '60dp',
    bottom: '100dp',
    backgroundColor: '#FFF'
});

var btnLbl = Ti.UI.createLabel({
    text: 'Take Photo'
});

takePhotoBtn.addEventListener('click', function(e){
    Ti.Media.takePicture()
});

takePhotoBtn.add(btnLbl);
overlay.add(takePhotoBtn);

$.back.addEventListener('click', showCamera);

$.index.open();

function showCamera(){
    Ti.Media.showCamera({
        success: function(event){
            var imageData = event.media;
            $.resultImg.setImage(imageData);
            Ti.Media.hideCamera();
        },
        error: function(error){
            Ti.API.info('Error: ' + JSON.stringify(error));
        },
        overlay : overlay,
        saveToPhotoGallery: false,
        allowEditing: false,
        mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO],
        showControls : false,
        autohide : false,
        //make the picture inside the camera smaller so that we 
        //can than place an overlay around it
        transform: Ti.UI.create2DMatrix({
            scale : 0.5
        })
    });

    Ti.Media.switchCamera(Ti.Media.CAMERA_FRONT);   
}

在 index.xml 中

<Alloy>
    <Window class="container">
        <Button id="back" title="Start camera"/>
        <ImageView id="resultImg"/>
    </Window>
</Alloy>

并非每次拍摄时都会发生这种情况,但可能每 10 次发生一次。请帮忙!!!

【问题讨论】:

    标签: ios7 titanium ios-camera


    【解决方案1】:

    当您连续拍摄多张照片时,iPhone 在处理之前的照片时内存不足。当您使用 Objective-C 时,您可以使用以下代码添加观察者:

    [[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(cameraIsReady:)
                                             name:AVCaptureSessionDidStartRunningNotification object:nil];
    

    但是,此 API 未在 Titanium 中实现,因此现在要解决此问题,您必须等待几秒钟以显示用户快速信息,然后重试。

    【讨论】:

    • 我已经在钛中解决了这个问题,方法是在实例化相机之后添加第二个超时,然后再将其从后转到前,然后再等待 500 毫秒,然后让 takePicture 事件通过。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-18
    • 2012-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多