我的iOS应用程序支持景观和肖像。splash屏幕、登录视图和主页视图都是肖像。
现在,如果我旋转设备,以景观和启动应用程序,所有三个视图是和保持在肖像,这是什么是必要的。但是,如果我启动应用程序的肖像和在飞溅屏幕,我旋转设备景观,登录屏幕显示在景观,然后自动移动到肖像。同样的主屏幕(自动登录,当用户已经登录并重新打开应用程序,它直接进入主屏幕)。
我用这个
[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationPortrait] forKey:@"orientation"];在viewDidLoad,viewDidAppear,viewWillAppear和viewWillDisappear。我还用了
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}所以,我想要达到的是保持在纵向的看法,即使我旋转设备在飞溅屏幕。
谢谢。
发布于 2015-10-02 15:09:43
导致问题的是应用程序的流程出现了问题。Ryan和Soberman提供的解决方案是有帮助的。这些代码行应该可以很好地使用supportedInterfaceOrientations NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; [[UIDevice currentDevice] setValue:value forKey:@"orientation"];。
发布于 2015-09-29 13:21:49
尝试将其放在viewDidLoad调用中:
// Change to portrait if in landscape mode
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
}记住在supportedInterfaceOrientations中调用超级程序
-(NSUInteger)supportedInterfaceOrientations{
[super supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}希望这能有所帮助。
发布于 2015-09-29 13:47:49
您应该重写viewController的shouldAutorotate方法,并返回到那些控制器中的NO,您不想旋转这些控制器。
编辑:尝试注释掉shouldAutorotate方法并实现
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}https://stackoverflow.com/questions/32845024
复制相似问题