2012-08-29 17 views
5

Tôi đang sử dụng iOS 6.0 beta và xoay vòng của tôi không hoạt động nữa.Tôi có thể thiết lập một UINavigationControllers được hỗ trợOrientations ở đâu?

Tôi có thể đặt UINavigationControllers supportsOrientations ở đâu?

Theo điều này http://news.yahoo.com/apple-ios-6-beta-3-changes-182849903.html Bộ điều khiển UINavigation không tham khảo ý kiến ​​con cái của họ để xác định xem chúng có nên tự động kiểm tra hay không.

Tôi không sử dụng shouldAutorotateToInterfaceOrientation: nữa vì nó không còn được dùng nữa. Thay vào đó tôi đang sử dụng supportedInterfaceOrientations: và shouldAutoRotate: và chúng hoạt động tốt cho đến khi tôi đặt ViewController vào trong một NavigationController (như một Child). Từ đó trên các định hướng được chỉ định trong ViewController không hoạt động nữa. Dường như nó đang sử dụng các hướng được thiết lập bởi bộ điều khiển điều hướng (UIInterfaceOrientationMaskAllButUpsideDown)

Làm thế nào tôi có thể đặt InterfaceOrientations cho NavigationController để ViewControllers của tôi bị khóa theo hướng dọc?

Tôi có phải phân lớp UINavigationController và đặt InterfaceOrientations ở đó không? Không phải là thực tế xấu để phân lớp UINavigationController vẫn còn trong iOS 6.0?

Cảm ơn sự giúp đỡ của bạn!

Chúc mừng!

Trả lời

4

Subclass UINavigationController

//OnlyPortraitNavigationController.h

@interface OnlyPortraitNavigationController : UINavigationController 

//OnlyPortraitNavigationController.m

@implementation OnlyPortraitNavigationController 

- (BOOL)shouldAutorotate { 
    return NO; 
} 

-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait; //for locked only Portrait 
} 

hiện phân lớp mới navigationController với chân dung của bạn ViewController

SomeViewController *onlyPortraitVC = [[SomeViewController alloc]init]; 

OnlyPortraitNavigationController *portraitNav = [[OnlyPortraitNavigationController alloc]initWithRootViewController:onlyPortraitViewController]; 

[self presentViewController:portraitNav animated:YES completion:NULL]; 

đây là công việc trên ứng dụng của tôi hy vọng nó có thể giúp bạn.

+0

làm việc tốt với tôi là tốt, cảm ơn bạn. –

9

Nếu bạn muốn nó tham khảo ý kiến ​​đó là trẻ em một lần nữa bạn có thể thêm một thể loại để UINavigationController

@implementation UINavigationController (Rotation_IOS6) 

-(BOOL)shouldAutorotate 
{ 
    return [[self.viewControllers lastObject] shouldAutorotate]; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return [[self.viewControllers lastObject] supportedInterfaceOrientations]; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
} 

@end 
+5

Thường là một ý tưởng tồi khi sử dụng các danh mục để ghi đè lên các phương thức của một lớp, đặc biệt là một phương thức được tích hợp vào hệ điều hành. Tạo một lớp con thay thế. –

+2

Tôi đồng ý với điều đó ... cuối cùng nó phụ thuộc vào hoàn cảnh của bạn. Đây chắc chắn là một sửa chữa tương thích nhanh cho một dự án lớn. – Anthony

+1

Tại sao đây là một ý tưởng tồi? Nó là người duy nhất đã làm việc cho tôi cho đến nay và nó đã được đơn giản để thiết lập. Tôi đặt nó trong UITabBarController và viola của tôi, tôi có thể kiểm soát vòng quay của tất cả các quan điểm của tôi. –

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