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];
}
本文介绍了一种使用Objective-C通过反射机制来调用iOS设备的UIDevice类中的setOrientation方法实现设备方向固定为横屏右的方法。此方法适用于需要特定设备方向的应用场景。


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



