ios6/ios7 畫面旋轉的問題


from:http://blog.sina.com.cn/s/blog_71715bf801019oye.html html


在ios5下畫面的旋轉都是shouldAutorotateToInterfaceOrientation來控制的,可是這個函數在ios6下不起做用。ios

在ios6下使用supportedInterfaceOrientations、shouldAutorotate來控制。app

若是單一的控制畫面那麼只須要加在上面兩個函數。以下函數

- (BOOL)shouldAutorotate {  ui

  

    return YES;  spa

}  .net

  1.   

  2. - (NSUInteger)supportedInterfaceOrientations {  orm

  3.   

  4.     return UIInterfaceOrientationMaskAll;  htm

  5. }  blog

 

若是是含有UINavigationController、UITabBarController的話,那麼修改部分就多了。

用其派生類的,在派生類中增長上面的supportedInterfaceOrientations、shouldAutorotate函數。

下面如MyNavigationController就是UINavigationController   的派生類。
修改部分以下

 1:在舊的程序中AppDelegate的部分如

定義的 UINavigationController            *navigationController;

  1. [window addSubview:[navigationController view]];  //不能旋轉  

改成

 

MyNavigationController            *myNavigationController;

  1. self.window.rootViewController = self.myNavigationController;  


 

派生類主要部分爲

  1. #import "MyNavigationController.h"  

  2.   

  3. @interface MyNavigationController ()  

  4.   

  5. @end  

  6.   

  7. @implementation MyNavigationController  

  8.   

  9. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil  

  10. {  

  11.     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  

  12.     if (self) {  

  13.         // Custom initialization  

  14.     }  

  15.     return self;  

  16. }  

  17.   

  18. - (void)viewDidLoad  

  19. {  

  20.     [super viewDidLoad];  

  21.     // Do any additional setup after loading the view.  

  22. }  

  23.   

  24. -(BOOL)shouldAutorotate  

  25. {  

  26.     return [self.viewControllers.lastObject shouldAutorotate];  

  27. }  

  28.   

  29. -(NSUInteger)supportedInterfaceOrientations  

  30. {  

  31.     return [self.viewControllers.lastObject supportedInterfaceOrientations];  

  32. }  

  33.   

  34. -(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation  

  35. {  

  36.     return [self.viewControllers.lastObject preferredInterfaceOrientationForPresentation];  

  37. }  

  38.   

  39. - (void)didReceiveMemoryWarning  

  40. {  

  41.     [super didReceiveMemoryWarning];  

  42.     // Dispose of any resources that can be recreated.  

  43. }  

  44.   

  45. @end  


這樣就能控制全部的控制畫面中的旋轉了,固然別忘了在每一個控制畫面都增長旋轉的函數。

 

根據多篇文章改寫的,目前根據這樣的方式,可以解決本身目前的問題,

若是你們還有更好的方式,還須要多指教。

官方

http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/RespondingtoDeviceOrientationChanges/RespondingtoDeviceOrientationChanges.html#//apple_ref/doc/uid/TP40007457-CH7-SW1

相關文章
相關標籤/搜索