2014-06-11 19 views

Trả lời

3

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 helpthis 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; 
} 
+0

Tôi viết những dòng này trong sence khác: – SuperHappy

+0

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

+0

Nó hoạt động. Cảm ơn rất nhiều! – echo

13

câu trả lời của tôi là đơn giản hơn, bên dưới mã. Điều này làm việc trong iOS8 (giống XCode6 GM).

HogeViewController *vc = [[HogeViewController alloc] init]; 
vc.modalPresentationStyle = UIModalPresentationOverFullScreen; 
[self presentViewController:vc animated:NO completion:nil]; 
+1

nếu bạn xoay ứng dụng của mình ở chế độ xem vc, điều gì đã xảy ra? Trong ứng dụng của tôi nó xoay khi phương thức - (BOOL) nênAutorotate { trả về KHÔNG; } – SuperHappy

+0

đọc khoảng 6 giải pháp ... không ai làm việc nhưng điều này. Big hug – braden

+0

tôi nợ bạn cuộc sống của tôi –

Các vấn đề liên quan