UIImagePickerController's shutter

▼魔方 西西 提交于 2019-12-04 12:54:27

The same was happening to me after locking/unlocking the app, it looks like the shutter opens on viewDidAppear.

So, I subscribed my parent view controller to UIApplicationDidBecomeActiveNotification and re-execute manually the viewWillAppear and viewDidAppear methods of the controller containing the UIImagePickerController

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(applicationBecomeActive)
                                             name:UIApplicationDidBecomeActiveNotification
                                           object:nil];

.
. 
.

- (void)applicationBecomeActive {
    if (imagePicker_)
        [imagePicker_ openShutter];
}

And then on the controller containing the UIImagePickerController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [imagePickerController_ viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [imagePickerController_ viewDidAppear:animated];
    imagePickerController_.cameraFlashMode = cameraFlashMode_;
    imagePickerController_.cameraDevice = cameraDevice_;
}
- (void)openShutter {
    [imagePickerController_ viewWillAppear:YES];
    [imagePickerController_ viewDidAppear:YES];
}

PS: If you try this, don't forget to remove the observer

[[NSNotificationCenter defaultCenter] removeObserver:self];

Hope this helps

If you are presenting the UIImagePickerController not modally (the recommended way), then you can either call the viewDidAppear and willAppear manually, or add the UIImagePickerController as child view controller from where you are presenting .

[thePresentingViewCotnroller addChildViewController:imagePickerController];

after this you can add the view from the imagePickerController as a subview, this will make the view life cycle methods (viewWillAppear, didAppear and disappear) called automatically.

Avinash

Try adding auto release when you initialize the UIImagePickerController:

UIImagePickerController *pickerController = [[[UIImagePickerController alloc] init] autorelease];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!