UIImagePickerController takePicture Dismisses Controller

时间:2017-04-02 00:30:32

标签: ios objective-c uiimagepickercontroller ios-camera

我有一个很好的自定义UIImagePickerController,只是我面临一个我认为应该相当简单的问题 - 我还没有找到解决方案。

触摸我自定义添加的“照片”按钮后,我将其定位到UIIPC的takePicture方法中。这是我的代码

@interface CustomCameraController ()

@end

@implementation CustomCameraController {
    CGFloat width, height;
}

- (instancetype)init {

    if (self = [super init]) {

        width = self.view.frame.size.width, height = self.view.frame.size.height;
        self.allowsEditing = YES;
        self.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.showsCameraControls = NO;
        self.toolbarHidden = YES;

        [self buildCameraOverlay];

    }
    return self;
}

- (void)buildCameraOverlay {

    UIView *customOverlay = [UIView alloc] ...
    // ... Custom overlay setup done here

    _takePhoto = [[CustomButton alloc] initWithFrame:CGRectMake(0, 0, heightBottomBar*.5, heightBottomBar*.5)];
    _takePhoto.center = CGPointMake(bottomBar.frame.size.width/2, bottomBar.frame.size.height/2);
    [_takePhoto setImage:[UIImage imageNamed:@"camera button icon"] forState:UIControlStateNormal];
    [_takePhoto addTarget:self action:@selector(takePicture) forControlEvents:UIControlEventTouchUpInside];
    [bottomBar addSubview:_takePhoto];

    // ... 

    self.cameraOverlayView = customOverlay;
}

这是在我的自定义控制器CustomCameraController init调用中完成的。

问题是,在通过takePicture拍摄照片后,相机快门熄灭,一切正常,但控制器自行解除。我试图找出如何在拍照后立即停止关闭,所以我可以A)呈现拍摄的照片,并且B)给用户选择图像或取消并重新拍摄另一张图像(返回到相机)

如果有人知道为什么会发生这种情况或我错过/做错了什么,请告诉我。我确信这是一个简单的答案 - 似乎无法弄明白。谢谢!

1 个答案:

答案 0 :(得分:1)

这种奇怪行为的最常见原因通常是缺少委托方法(在这种情况下为UIImagePickerController)或者执行错误。

相关问题