作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有 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/
我正在使用 Shutter,我非常喜欢它。我将它安装在我的新笔记本电脑上,但无法正常工作。当我打开快门并尝试截取屏幕截图时,它显示错误消息“打开/home/username/Pictures 时出错”
我是一名优秀的程序员,十分优秀!