標籤:io ar os sp for on bs 代碼 ef
第一種:手動的設定介面元素的旋轉,包括狀態列、導覽列和視圖。以下代碼為從豎屏設定為橫屏,座標系是以豎屏的為基準,所以會出現負數的座標值。
//設定狀態列旋轉
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeRightanimated:YES];
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
//設定旋轉動畫
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
//設定導覽列旋轉
self.navigationController.navigationBar.frame = CGRectMake(-204, 224, 480, 32);
self.navigationController.navigationBar.transform = CGAffineTransformMakeRotation(M_PI*1.5);
//設定視圖旋轉
self.view.bounds = CGRectMake(0, -54, self.view.frame.size.width, self.view.frame.size.height);
self.view.transform = CGAffineTransformMakeRotation(M_PI*1.5);
[UIView commitAnimations]
第二種切換到下一個頁面強制轉橫屏
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIInterfaceOrientationLandscapeRight;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
ios開發強制橫豎屏轉換