IOS开发中强制横屏、竖屏、转屏的设置操作
来源:爱站网时间:2020-07-22编辑:网友分享
IOS项目中有很多项目的接口只支持垂直屏幕,只有少数接口需要在水平和垂直屏幕之间切换,本文主要为大家介绍了IOS开发中强制横屏、竖屏、转屏的设置操作,非常有参考的价值,大家可以进入下文详细的了解一下。
IOS项目中有很多项目的接口只支持垂直屏幕,只有少数接口需要在水平和垂直屏幕之间切换,本文主要为大家介绍了IOS开发中强制横屏、竖屏、转屏的设置操作,非常有参考的价值,大家可以进入下文详细的了解一下。
强制横屏:
[self interfaceOrientation:UIInterfaceOrientationLandscapeRight];
强制竖屏:
[self interfaceOrientation:UIInterfaceOrientationPortrait];
强制转屏
- (void)interfaceOrientation:(UIInterfaceOrientation)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]];
int val = orientation;
// 从2开始是因为0 1 两个参数已经被selector和target占用
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
}
以上就是爱站技术频道小编为大家介绍的IOS开发中强制横屏、竖屏、转屏的设置操作,希望通过本文的介绍,大家都有了一定的了解。
