gpt4 book ai didi

iOS UIInterfaceOrientation

转载 作者:行者123 更新时间:2023-11-28 21:38:55 24 4
gpt4 key购买 nike

我的 iOS 应用同时支持横向和纵向。初始屏幕、登录 View 和主页 View 都是纵向的。

现在,如果我将设备旋转到横向并启动应用程序,所有三个 View 都是并保持纵向,这是需要的。但是如果我以纵向启动应用程序并且在启动画面期间我旋转设备以横向登录屏幕显示为横向然后自动移动到纵向。主屏相同(自动登录,当用户已经登录并重新打开应用程序时,它直接进入主屏幕)。

我用过这个

[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationPortrait] forKey:@"orientation"];

在 viewDidLoad、viewDidAppear、viewWillAppear 和 viewWillDisappear 中。我也用过

-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}

因此,我想要实现的是即使我在启动画面期间旋转设备也能保持纵向 View 。

谢谢。

最佳答案

尝试将其放入您的 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 中调用 super

-(NSUInteger)supportedInterfaceOrientations{
[super supportedInterfaceOrientations];
return UIInterfaceOrientationMaskPortrait;
}

希望对您有所帮助。

关于iOS UIInterfaceOrientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32845024/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com