iOS7中實現子視圖旋轉方向控制

來源:互聯網
上載者:User

   為了能夠讓父視圖(地圖視圖)實現隨意旋轉,而子視圖按照某種固定的方向(豎屏)顯示尋找了好些方案,最後發現在iOS7中其實很簡單
-(BOOL)shouldAutorotate{    if([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft ||[[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight)    {        return NO;    }    else{        return YES;    }}
另外有人在iOS6中使用如下方式
static CGSize appScreenSize;static UIInterfaceOrientation lastOrientation; +(CGSize) screenSize{UIInterfaceOrientation orientation =[UIApplication sharedApplication].statusBarOrientation;if(appScreenSize.width==0 || lastOrientation != orientation){appScreenSize = CGSizeMake(0, 0);CGSize screenSize = [[UIScreen mainScreen] bounds].size; // 這裡如果去掉狀態列,只要用applicationFrame即可。if(orientation == UIDeviceOrientationLandscapeLeft ||orientation == UIDeviceOrientationLandscapeRight){// 橫屏,那麼,返回的寬度就應該是系統給的高度。注意這裡,全屏應用和非全屏應用,應該注意自己增減狀態列的高度。appScreenSize.width = screenSize.height;appScreenSize.height = screenSize.width;}else{appScreenSize.width = screenSize.width;appScreenSize.height = screenSize.height;}lastOrientation = orientation;}return appScreenSize;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.