// 能否自动旋转
-(BOOL)shouldAutorotate{
return NO;
}
// 支持的屏幕方向
-(UIInterfaceOrientationMask)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
// 默认的屏幕方向
-(UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
// 强制屏幕旋转
- (void)setLandscape:(UIDeviceOrientation)orientation {
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
[invocation setArgument:&orientation atIndex:2];
[invocation invoke];
}
}
本文介绍了一个iOS应用如何通过代码控制屏幕的方向,包括禁止自动旋转、设置支持的屏幕方向及默认的屏幕方向。此外还提供了一个示例来演示如何强制设备进行屏幕方向的切换。
5

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



