1.界面旋转,MainScreen的宽高不变,键盘位置不变
CGFloat duration = [UIApplication sharedApplication].statusBarOrientationAnimationDuration;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:duration];
self.view.transform =CGAffineTransformMakeRotation(M_PI/2);
[UIView commitAnimations];
2.界面旋转,MainScreen的宽高改变,键盘位置不变
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]; }
3.界面旋转,MainScreen的宽高改变,键盘位置改变
a.General—>中勾选Lnadscape Left/Lnadscape Right,默认是勾选上了的

b.控制器中实现以下两个方法:
// 支持设备自动旋转 - (BOOL)shouldAutorotate { return YES; } /** * 设置特殊的界面支持的方向,这里特殊界面只支持Home在右侧的情况 */ - (UIInterfaceOrientationMask)supportedInterfaceOrientations { return UIInterfaceOrientationMaskLandscapeRight; }
PS:如何判断当前是否横屏,一下3个方法都可以
self.interfaceOrientation(iOS 2.0~8.0)
[UIApplication sharedApplication] statusBarOrientation]
[[UIDevice currentDevice] orientation]
本文详细介绍了在iOS开发中实现界面旋转的三种不同场景:保持MainScreen宽高不变、宽高改变但键盘位置不变、以及宽高和键盘位置均改变的方法。通过具体的代码示例,展示了如何使用UIView动画、UIDevice方向设置及UIViewController的旋转支持API来实现这些功能。
1万+

被折叠的 条评论
为什么被折叠?



