我有兩個視圖。非常簡單的設置只是玩相機膠捲。iOS:調用dismissModalViewController後屏幕不再接收觸摸
一種觀點將彈出使用相機膠捲:這是由UIButton
觸發
[self presentViewController:self.imagePicker animated:NO completion:nil];
。它帶來了相機,一切都很好。
拍攝照片後,我打電話以下駁回控制器:
[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];
}
有關按鈕的日誌信息控制檯在模態被解除後控制檯。按鈕的框架是否被移位?按鈕的框架是否與按鈕的約束相匹配? – bilobatum
@bilobatum我剛查過。 Button的框架在前後都是相同的。謝謝。 – Unheilig