gpt4 book ai didi

iphone - iPad 应用强制旋转

转载 作者:行者123 更新时间:2023-11-29 13:41:08 34 4
gpt4 key购买 nike

我有一个简单的导航应用程序,其中 95% 的 View 以横向模式显示。对于仅在纵向模式下显示有意义的一个 View ,我在其中插入了以下代码:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

问题是,当应用程序导航到 View (从横向 View )时,它不会将方向切换为纵向,只有当设备旋转时,它才会捕捉到纵向并保持纵向。是否可以强制它在加载 View 时以纵向模式加载?

提前致谢

最佳答案

我认为您应该通过:UIViewController 类的shouldAutoRotateToInterfaceOrientation 方法。

如果您的 UIView 支持这些方向,则此函数返回 YES。如果您仅对纵向方向返回 YES,则 iPhone 将自动置于该方向。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

关于iphone - iPad 应用强制旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9104003/

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