簡體   English   中英

退出自定義模式視圖控制器

[英]Dismissing custom modal view controller

我以這種方式加載UIImagePickerController:

- (void) launchCamera {

// Set up the camera
CustomCamera *cameraController = [[CustomCamera alloc] init];
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraController.delegate = self;

cameraController.showsCameraControls = NO;
cameraController.navigationBarHidden = YES;
cameraController.toolbarHidden = YES;

// overlay on top of camera lens view
UIImageView *cameraOverlayView = [[UIImageView alloc] initWithImage:[UIImage   imageNamed:@"camera_overlay.png"]];
cameraOverlayView.alpha = 0.0f;
cameraController.cameraOverlayView = cameraOverlayView;

// animate the fade in after the shutter opens
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:2.2f];
cameraOverlayView.alpha = 1.0f;
[UIView commitAnimations];

[customCamera presentModalViewController:cameraController animated:YES];
}

問題是我不知道如何解散它。 當我嘗試

 [cameraController dismissViewControllerAnimated:YES completion: nil];

仍未從屏幕上刪除cameracontroller

要以模態顯示視圖控制器,應使用以下方法:

 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);

要關閉模式視圖控制器,應使用以下方法:

- (void)dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion NS_AVAILABLE_IOS(5_0);

根據這些方法( UIViewController.h )上方的內聯注釋:

The next two methods are replacements for presentModalViewController:animated and dismissModalViewControllerAnimated: The completion handler, if provided, will be invoked after the presented controllers viewDidAppear: callback is invoked.

這是您的代碼的問題所在:

您正在使用不推薦使用的方法來呈現模態視圖控制器,並嘗試使用新方法將其關閉...這將無法工作。

改變這個

[customCamera presentModalViewController:cameraController animated:YES];

有了這個

[self presentViewController:cameraController animated:YES completion:nil];

並關閉此代碼

[self dismissViewControllerAnimated:YES  completion:nil];

我希望這能幫到您

[self dismissViewControllerAnimated:YES  completion:nil];

快樂的編碼...

如果要將ViewController添加為模態-使用:

 [self dismissModalViewControllerAnimated:YES];

在您的視圖控制器中。

請注意,iOS 6.0中已不推薦使用名稱為“ Modal”的兩個功能。 請改用presentViewController:animated:completion:。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM