生活随笔
收集整理的這篇文章主要介紹了
设置ios6中UIViewController旋转
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
?1、首先在appDelegate中,把view添加到window中有兩種方式、
?
?
?
[cpp]view plaincopyprint?
?
self.window.rootViewController = self.view;[self.window addSubview:self.view.view];?
但是如果用第二種的話,在ios6.0中再去設置屏幕旋轉(zhuǎn)是沒有任何效果的,必須使用第一種。在ios6.0以前的版本是沒有這種分別的。
2、 開啟全部方向屏幕旋轉(zhuǎn)的方式
iOS6.0之前: 只需這個方法返回yes即可
?
?
[cpp]view plaincopyprint?
?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{returnYES;}?
iOS6.0中 需要這三個方法一起使用才可以
?
?
[cpp]view plaincopyprint?
?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{return(toInterfaceOrientation != UIInterfaceOrientationMaskPortraitUpsideDown);}- (BOOL)shouldAutorotate{returnYES;}- (NSUInteger)supportedInterfaceOrientations{returnUIInterfaceOrientationMaskAllButUpsideDown;}?
當然了關(guān)閉全部方向屏幕旋轉(zhuǎn)的方式則把上面的返回值改為no即可
iOS6.0之前:
?
?
[cpp]view plaincopyprint?
?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{returnNO;}?
iOS6.0中
?
?
[cpp]view plaincopyprint?
?
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{return(toInterfaceOrientation == UIInterfaceOrientationPortrait);}- (BOOL)shouldAutorotate{returnNO;}- (NSUInteger)supportedInterfaceOrientations{returnUIInterfaceOrientationMaskPortrait;//只支持這一個方向(正常的方向)}?
使用屏幕旋轉(zhuǎn)常用的方法
?
[cpp]view plaincopyprint?
?
?
//視圖旋轉(zhuǎn)之前自動調(diào)用-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {NSLog(@"視圖旋轉(zhuǎn)之前自動調(diào)用");}//視圖旋轉(zhuǎn)方向發(fā)生改變時會自動調(diào)用-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{NSLog(@"視圖旋轉(zhuǎn)方向發(fā)生改變時會自動調(diào)用");}//視圖旋轉(zhuǎn)完成之后會自動調(diào)用?-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {NSLog(@"視圖旋轉(zhuǎn)完成之后自動調(diào)用");}
轉(zhuǎn)載于:https://blog.51cto.com/zqlicoder1314/1138109
總結(jié)
以上是生活随笔為你收集整理的设置ios6中UIViewController旋转的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。