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