2012-10-08 14 views
6

vì iOS6 tôi có vấn đề lớn với xoay vòng. Tôi đã triển khai tất cả các phương thức xoay mới (shouldAutorotate, preferredInterfaceOrientationForPresentation, supportedInterfaceOrientation), nhưng tất cả các khung nhìn vẫn đang xoay. Điều thú vị là rằng các chế độ xem đang giữ kích thước của chúng và phần còn lại của Cửa sổ (trong Phong cảnh) là màu đen.ios 6 Ứng dụng đang quay, ngay cả với shouldAutorotate: NO

Thats cách tôi thực hiện nó, có gì sai không?

#pragma mark - 
#pragma mark - InterfaceOrientation iOS 5 
//Deprecated in iOS 6 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

#pragma mark - 
#pragma mark - InterfaceOrientation iOS 6 

- (BOOL)shouldAutorotate{ 
    return NO; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{ 
    return UIInterfaceOrientationPortrait; 
} 

- (NSUInteger)supportedInterfaceOrientations{ 
    return UIInterfaceOrientationMaskPortraitUpsideDown; 
} 

Cảm ơn bạn đã giúp đỡ mọi người.

+0

Không phải cụm từ cuối cùng là 'UIInterfaceOrientationMaskPortrait'? –

+0

Ok nếu nó xoay theo cả hai hướng dọc, nhưng không được xoay sang hướng ngang – Fry

+2

Chỉ cần cố gắng thay đổi hỗ trợ định hướng mặc định của ứng dụng tức là trong tệp plist dưới khóa 'Định hướng giao diện được hỗ trợ' chỉ chọn hai giao diện được hỗ trợ. Điều này sẽ giải quyết vấn đề của bạn :) –

Trả lời

9

tôi đã giải quyết được vấn đề bằng cách làm cho một hạng mục cho các navigationcontroller:

@implementation UINavigationController (iOS6fix) 

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

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

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

@end 

Nhờ mọi người cho câu trả lời!

+0

Tôi phải tạo một lớp con của UINavigationController và sử dụng object_setClass (.., ..) để đặt navigationController của tôi vào lớp đó. Tôi cũng đã triển khai 3 phương pháp đó. Tốt nhất bạn đánh dấu câu trả lời của bạn là câu trả lời được chấp nhận để mọi người có thể thấy coz dường như có rất nhiều sự nhầm lẫn và các vấn đề nảy sinh do sự thay đổi này – pnizzle

+0

Hoàn hảo, cảm ơn! – Fogmeister

+0

Làm việc như một sự quyến rũ - cảm ơn bạn rất nhiều .. – geekyaleks

-1
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    //Make sure your window to assgin the view controller object to rootViewController, Please don't add controller view as a sub view on window. 
    self.window.rootViewController = viewController; 
} 
0

Tôi cũng vậy, nó xoay ngay cả khi tôi chuyển nó thành NO.

Hai lựa chọn:

  1. đi đến thiết lập dự án của bạn và thay đổi định hướng tốt

  2. Hủy bỏ tất cả các phương pháp để dừng quay. Ngay cả khi họ được thiết lập để NO, họ xoay cho tôi.

0

Tôi đã sử dụng danh mục sau trên UIViewController để chỉ có cảnh quan trên iOS5 và 6. Có thể nó giúp người khác.

#import <UIKit/UIKit.h> 

@implementation UIViewController (iOS6fix) 

-(BOOL)shouldAutorotate 
{ 
    return YES; 
} 

-(NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationLandscapeLeft; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return UIInterfaceOrientationIsLandscape(interfaceOrientation); 
} 

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