2012-11-12 21 views
33

Với iPad với iOS6, chúng tôi có lỗi này, nơi một bộ điều khiển chế độ xem sẽ mở rộng ra toàn màn hình, ngay cả khi được yêu cầu sử dụng kiểu trình bày "biểu mẫu". Nhưng, điều này xảy ra chỉ khi có hai modals, một phụ huynh và con của nó.iOS 6: ModalPresentationStyle của modal của cha mẹ bị bỏ qua sau khi xoay

Vì vậy, đây là cách phương thức đầu tiên được tạo ra và trình bày:

UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease]; 
navigationController.modalPresentationStyle = UIModalPresentationFormSheet; 
[parentController presentModalViewController:navigationController animated:YES]; 
// parentController is my application's root controller 

Đây là cách phương thức trẻ được tạo ra và trình bày:

UINavigationController *navigationController = [[[UINavigationController alloc] initWithRootViewController:controller] autorelease]; 
navigationController.modalPresentationStyle = UIModalPresentationFormSheet; 
[parentController presentModalViewController:navigationController animated:YES]; 
// parentController is the navigationController from above 

Vì vậy, khi quay từ phong cảnh đến chân dung, các chế độ cha mẹ sẽ mở rộng thành toàn màn hình và vẫn như vậy ngay cả khi chúng tôi quay lại chế độ ngang.

Khi chúng ta có chính phương thức cha mẹ (không có phương thức con), thì nó hoạt động như mong đợi, là nó vẫn còn trong kiểu trang biểu mẫu.

Lưu ý rằng điều này chỉ xảy ra trên iOS6 (thiết bị và trình mô phỏng) và không xảy ra trên iOS 5 (giả lập và được báo cáo hoạt động bởi người thử nghiệm).

Cho đến nay, tôi đã thử các sau đây mà không thành công:

  • thiết wantsFullScreenLayout-NO
  • buộc wantsFullScreenLayout để luôn trở NO bằng cách ghi đè nó
  • Làm một số bộ điều khiển của tôi bên trong điều khiển chuyển hướng cũng chỉ định UIModalPresentationFormSheet
  • triển khai preferredInterfaceOrientationForPresentation
  • nâng cấp lên iOS 6.0.1

Cảm ơn!


CẬP NHẬT: Vì vậy, tôi thích những phản ứng từ các diễn đàn của Apple Developer (https://devforums.apple.com/message/748486#748486) để nó làm việc với nhiều phương thức lồng nhau.

- (BOOL) needNestedModalHack { 
    return [UIDevice currentDevice].systemVersion.floatValue >= 6; 
} 

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
              duration:(NSTimeInterval)duration { 

    // We are the top modal, make to sure that parent modals use our size 
    if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) { 
     for (UIViewController* parent = self.presentingViewController; 
      parent.presentingViewController; 
      parent = parent.presentingViewController) { 
      parent.view.superview.frame = parent.presentedViewController.view.superview.frame; 
     } 
    } 

    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
} 

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
           duration:(NSTimeInterval)duration { 
    // We are the top modal, make to sure that parent modals are hidden during transition 
    if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) { 
     for (UIViewController* parent = self.presentingViewController; 
      parent.presentingViewController; 
      parent = parent.presentingViewController) { 
      parent.view.superview.hidden = YES; 
     } 
    } 

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 
} 

- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    // We are the top modal, make to sure that parent modals are shown after animation 
    if (self.needNestedModalHack && self.presentedViewController == nil && self.presentingViewController) { 
     for (UIViewController* parent = self.presentingViewController; 
      parent.presentingViewController; 
      parent = parent.presentingViewController) { 
      parent.view.superview.hidden = NO; 
     } 
    } 

    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; 
} 
+2

Ai đó đã chỉ cho tôi diễn đàn nhà phát triển táo và tôi thấy điều này: https://devforums.apple.com/message/748486 – GenesisST

+2

Trình bày nhiều phương thức phá vỡ rõ ràng cách Apple nói bạn nên làm mọi thứ. Nếu bạn kết thúc làm những việc như thế này đi ngược lại lời khuyên của Apple thì mong đợi những vấn đề như thế này. Cũng xem xét bạn có thể có một thiết kế rất xấu. Nếu bạn muốn hiển thị nhiều viewControllers như thế này, bạn nên sử dụng ngăn chặn hoặc một navigationController trong một bản trình bày phương thức duy nhất. Bạn sẽ làm gì khi điều này lại bị hỏng trong iOS 6.3? – ader

+1

@Ade: Tài liệu này đề cập rằng có thể chuỗi các trình điều khiển chế độ xem phương thức: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/ uid/TP40007457-CH111-SW1 – GenesisST

Trả lời

0

Tôi có thể thấy 2 vấn đề ở đây.

1) trong iOS 6 phương pháp presentModalViewController:animated: bị phản đối, hãy thử sử dụng presentViewController:animated:completion: (mặc dù điều này có thể không giúp đỡ, bạn vẫn có thể muốn làm điều đó)

2) Trong iOS 6 bằng cách nào đó xuất hiện mà điều khiển chứa (chẳng hạn như UINavigationController) không gửi lại tin nhắn tự động cho con cái của họ. Thử subclassing các UINavigationController và xác định lại các phương pháp autorotation tương ứng được gửi đến tất cả các trẻ em. Điều này có thể giúp.

+0

1. Đồng ý. Vào thời điểm tôi viết bài này, chúng tôi vẫn hỗ trợ 4,3.

2. Tôi chưa gặp sự cố khi thử nghiệm và cho đến nay từ trường. Tôi sử dụng bộ điều khiển điều hướng rất nhiều. Có thể bộ điều khiển nội dung của tôi đủ chung và không có bất kỳ vấn đề nào ...

Tôi đoán chúng ta sẽ thấy với iOS7, vì Apple dường như thay đổi cách gọi quay vòng hoạt động với mọi phiên bản chính ... ;-) – GenesisST

7

Không chắc chắn nếu điều này nên được coi là một lỗi và tôi tò mò những gì iOS 7 sẽ mang lại, nhưng cách giải quyết hiện tại cho vấn đề này là đặt modalPresentationStyle thành UIModalPresentationCurrentContext cho child-viewController.

Set modalPresentationStyle = UIModalPresentationCurrentContext 

Điều này làm cho trẻ vẫn nuôi ong được trình bày dưới dạng FormSheet nhưng ngăn cha mẹ không bị thay đổi kích thước sang chế độ toàn màn hình.

Dirk

+0

giải quyết vấn đề của tôi. Tôi đã tạo trang tính từ một trang tính khác. Và sau khi thay đổi kích thước trang trang mẹ chiếm toàn bộ màn hình của tôi. – GxocT

-1

Bạn cần instanciate bộ điều khiển điều hướng của mình sau chế độ xem chính. Vì vậy, bạn sẽ có thể quản lý xoay trong mỗi chế độ xem.

Nếu AppDelegate RootViewController của bạn là bộ điều khiển điều hướng, bạn sẽ không thể quản lý xoay bằng các hàm gốc.

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