1.在AppDelegate.h 里添加标记
2.在AppDelegate.m 里添加这个方法
3.打开屏幕旋转
[(AppDelegate*)[UIApplication sharedApplication].delegate setAllowRotation:YES];
4.取消屏幕旋转
[(AppDelegate*)[UIApplication sharedApplication].delegate setAllowRotation:NO];
[[NSNotificationCenter defaultCenter] removeObserver:self];
if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) {
SEL selector = NSSelectorFromString(@"setOrientation:");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDeviceinstanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector];
[invocation setTarget:[UIDevice currentDevice]];
int val = UIInterfaceOrientationPortrait;
[invocation setArgument:&val atIndex:2];
[invocation invoke];
}
时间: 2024-11-03 21:02:00