Lưu ý rằng giải pháp này là cần thiết trên xcode6_beta7. Mới nhất xcode6 có kiểu UIModalPresentationOver * cố định. Vì vậy, tôi chỉ cần gán chúng cho myModalViewController.modalPresentationStyle và bây giờ nó hoạt động ok.
Cuối cùng làm cho nó hoạt động trong iOS 8 sau khi đọc UIPresentationController help và this post
appDelegate.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;
MyModalController *myModalController = [[MyModalController alloc] initWithNibName:@"MyModalController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myModalController];
navController.modalPresentationStyle = UIModalPresentationCustom;
navController.transitioningDelegate = myModalController;
[self.navigationController presentViewController:navController animated:YES completion:nil];
Bạn có thể làm cho các bộ điều khiển xem phương thức kế thừa từ UIViewControllerTransitioningDelegate
@interface MyModalController : UIViewController <UIViewControllerTransitioningDelegate>
và ghi đè presentationControllerForPresentedViewController: ...
-(UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
if (presented == self) {
return [[TransparentPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
} else {
return nil;
}
}
trở về một thể hiện của TransparentPresentationController mà kế thừa từ UIPresentationController
@interface TransparentPresentationController : UIPresentationController
và ghi đè shouldRemovePresentersView
- (BOOL) shouldRemovePresentersView {
return NO;
}
Nguồn
2014-09-05 18:24:49
Tôi viết những dòng này trong sence khác: – SuperHappy
Tôi viết những dòng này trong hai cảnh: Trong ViewController: - (IBAction) trình bày: (id) sender {// cảnh hai SecondViewController * controller = [[SecondViewController alloc] trong đó]; [bộ điều khiển hiện tại]; } Đối với hàng rào hai :- (void) hiện diện { UIViewController * root = [[[[UIApplication sharedApplication] delegate] window] rootViewController]; [self setTransitioningDelegate: self.transitionController]; self.modalPresentationStyle = UIModalPresentationCustom; [root presentViewController: tự động: YES complete: nil]; } Nhưng nó không làm phương pháp ủy nhiệm. Tại sao bạn lại đúng. – SuperHappy
Nó hoạt động. Cảm ơn rất nhiều! – echo