我们在appdelegate 里面用代码把屏幕转向禁止(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskPortrait; }
现在想要某一个界面支持转屏后横屏(UIInterfaceOrientationMaskPortrait
不能改,其他界面要求竖屏)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
//Appdelegate.h
@property(nonatomic,assign)BOOL Orientations;
//Appdelegate.m
(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { if(Orientations) { return UIInterfaceOrientationMaskAllButUpsideDown; } return UIInterfaceOrientationMaskPortrait;
}
//要旋转的页面中
UIDevice *device = [UIDevice currentDevice]; //Get the device object
[device beginGeneratingDeviceOrientationNotifications]; //Tell it to start monitoring the accelerometer for orientation
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; //Get the notification centre for the app
[nc addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:device];
AppDelegate *delegate=[[UIApplication sharedApplication]delegate];
delegate.Orientations=YES;
(void)orientationChanged:(NSNotification *)note {
UIDeviceOrientation o = [[UIDevice currentDevice] orientation];
switch (o) {
case UIDeviceOrientationPortrait: // Device oriented vertically, home button on the bottom
break;
case UIDeviceOrientationPortraitUpsideDown: // Device oriented vertically, home button on the top
break;
case UIDeviceOrientationLandscapeLeft: // Device oriented horizontally, home button on the right
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
break;
case UIDeviceOrientationLandscapeRight: // Device oriented horizontally, home button on the left
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
break;
default:
break;
}
}
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// 操作
return YES; // YES为允许横屏,否则不允许横屏
}
希望对你有帮助。