我有 UIImagePickerController 的错误,它的源类型是相机。有时 Controller 出现后,快门没有打开,我看不到相机视频信号,但拍摄的照片是正确的。
可能是我做错了什么?代码:
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.allowsEditing = NO;
cameraUI.showsCameraControls = NO;
cameraUI.delegate = self;
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
UIView *controlsView = [nibObjects objectAtIndex:0];
CGRect overlayViewFrame = cameraUI.cameraOverlayView.frame;
CGRect controlsFrame = CGRectMake(0.0, CGRectGetHeight(overlayViewFrame) - 54.0,
CGRectGetWidth(overlayViewFrame), 54.0);
controlsView.frame = controlsFrame;
[cameraUI.cameraOverlayView addSubview:controlsView];
[self presentModalViewController: cameraUI animated: YES];
}
最佳答案
锁定/解锁应用程序后,我也发生了同样的情况,看起来快门在 viewDidAppear 上打开。
因此,我将父 View Controller 订阅到 UIApplicationDidBecomeActiveNotification
并手动重新执行包含 UIImagePickerController 的 Controller 的 viewWillAppear 和 viewDidAppear 方法
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
.
.
.
- (void)applicationBecomeActive {
if (imagePicker_)
[imagePicker_ openShutter];
}
然后在包含 UIImagePickerController 的 Controller 上
- (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:如果你尝试这个,不要忘记移除观察者
[[NSNotificationCenter defaultCenter] removeObserver:self];
希望这可以帮助
关于objective-c - UIImagePickerController 的快门,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8998605/