2013-10-16 79 views
2

我有兩個視圖。非常簡單的設置只是玩相機膠捲。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]; 
} 
+0

有關按鈕的日誌信息控制檯在模態被解除後控制檯。按鈕的框架是否被移位?按鈕的框架是否與按鈕的約束相匹配? – bilobatum

+0

@bilobatum我剛查過。 Button的框架在前後都是相同的。謝謝。 – Unheilig

回答

1

你應該在選擇器被調用dismissViewControllerAnimated通過UIImagePickerControllerDelegate方法不self

[picker dismissViewControllerAnimated:NO completion:nil]; 

,或者如果你保持對它的引用:

[self.imagePicker dismissViewControllerAnimated:NO completion:nil]; 

編輯:

根據修改後的代碼,我相信

self.imagePicker.cameraOverlayView = cameraOverlay; 

應該是:

self.imagePicker.cameraOverlayView = cameraOverlay.view; 

而且這將導致一個+2引用計數,並會泄漏,如果你不使用ARC:

self.imagePicker = [[UIImagePickerController alloc] init]; 

它應該是正確的引用計數:

UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
self.imagePicker = picker; 
[picker release]; 
+0

謝謝,我已經嘗試了上述兩種方法,但都沒有成功。我試圖在'touchesBegan'中做一個'NSLog'。該視圖在控制器被解僱之後確實接受了觸摸,但是該方法不再被調用。 – Unheilig

+0

然後你需要發佈更多的代碼,因爲你正在做其他事情來禁用視圖。 – Joel

+0

請使用代碼查看更新後的問題。謝謝。 – Unheilig

相關問題