2012-10-30 48 views
0

我想知道設備的方向,當視圖出現。 以前有可能使用shouldAutorotateToInterfaceOrientation方法,但在IOS 6中不推薦使用。我想知道設備的方向,當視圖出現IOS 6

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 

    if (interfaceOrientation==UIInterfaceOrientationPortrait ||interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) { 
     DashBtn.hidden=NO; 
    } 
    else 
    { 
     DashBtn.hidden=YES; 
     if (self.popoverControllerMain) { 
      [self.popoverControllerMain dismissPopoverAnimated:YES]; 
     } 


    } 
    return YES; 
} 

我檢查了所有的帖子 即讓RootViewController的和

- (BOOL)shouldAutorotate { 
    return NO; 
}// this method is not called 

- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationMaskPortrait; 
} 

回答

1

創建的UINavigationController的類別,並添加以下代碼@implementation的UINavigationController(Rotation_IOS6)

- (BOOL)shouldAutorotate { 返回[自我.viewControllers lastObject] shouldAutorotate]; }

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

  • (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 返回[[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; }

@end

1

嘗試使用

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

,而不是

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

參考http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html瞭解詳情。

+0

但是當第一個視圖加載...即不爲旋轉裝置 – shyla

+0

@shyla你必須寫在'代碼,它不會叫 - (無效)viewDidLoad'或' - (空隙)viewWillAppear中:(BOOL)animated' –

0

知道設備定向最好的辦法是

[[UIApplication sharedApplication] statusBarOrientation]