iOS7中實現子視圖旋轉方向控制 – iPhone手機開發技術文章 iPhone軟體開發教學課程

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

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *