ios开发强制横竖屏转换
第一种:手动的设置界面元素的旋转,包括状态栏、导航栏和视图。以下代码为从竖屏设置为横屏,坐标系是以竖屏的为基准,所以会出现负数的坐标值。
//设置状态栏旋转
[[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];
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。