你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS7中實現子視圖旋轉方向控制

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

編輯:IOS開發綜合
   為了能夠讓父視圖(地圖視圖)實現隨意旋轉,而子視圖按照某種固定的方向(豎屏)顯示尋找了好些方案,最後發現在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;
}


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved