我有两种看法。非常简单的设置只是为了玩相机胶卷。
一个视图将使用以下方法调出相机胶卷:
[self presentViewController:self.imagePicker animated:NO completion:nil];
这是由 a 触发的UIButton
。它带来了相机,一切都很好。
拍照后,我正在调用以下命令来关闭控制器:
[self dismissViewControllerAnimated:NO completion:nil];
同样,一切正常。
但是在模态视图关闭后,调出imagePicker
控制器的视图不再接收触摸(UIButton
将不再再次调出相机)。
只有当我切换到另一个视图并返回时,它才会再次开始接收触摸。
我一直在寻找解决这个问题的方法,但没有成功找到任何东西。提前致谢。
编辑(添加代码):
在 CameraController.m 中
这是调出相机胶卷的地方
(UIViewController
符合的
子类<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
)
//UIButton that brings up the imagePicker
- (IBAction)useCamera
{
[self prepareImagePicker];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
//Initializing ImagePicker
- (void)prepareImagePicker
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera])
{
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage, nil];
self.imagePicker.delegate = self;
OverlayCameraView *cameraOverlay = [[OverlayCameraView alloc] initWithFrame:(CGRect){{0, 0}, 320, 480} andTheCameraController:self];
self.imagePicker.cameraOverlayView = cameraOverlay;
}
}
//Delegate Method when a picture is taken
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
self.imagePicker.delegate = nil;
[picker dismissViewControllerAnimated:NO completion:nil];
self.imagePicker = nil;
self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
}
在 OverlayCameraView.m 中
//Camera Overlay Class (Subclass of UIView)
- (id)initWithFrame:(CGRect)frame andTheCameraController:(CameraController*)cameraController
{
if ((self = [super initWithFrame:frame]))
{
self.camera = cameraController;
//.…2 UIButtons set up
}
return self;
}
//Overlay Cancel Button
- (void) cancel
{
[self.camera dismissViewControllerAnimated:NO completion:nil];
}
//Overlay Take Picture Button
- (void) takeAPicture
{
[self.camera.imagePicker takePicture];
}