gpt4 book ai didi

ios - Xcode IOS Lock 某些方向为纵向,某些方向为横向

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:02:38 25 4
gpt4 key购买 nike

我正在开发一个具有大约 12 个 View 的应用程序。我希望有些只是肖像,有些是风景。

我如何将某些 View 的方向锁定为纵向,而将其他 View 的方向锁定为横向?

我尝试了前面示例中的以下代码,但它没有锁定方向。

    [[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationLandscapeLeft]
forKey:@"orientation"];

最佳答案

经过将近 24 小时的尝试,我终于解决了这个问题。对于一个“ShouldAutoRotate”永远不会被调用。这就是我在任何地方都能找到的“只需添加 shouldAutoRotate”……没有用。我也不确定为什么人们不赞成我的问题。

对我有用的是将下面的方法添加到我的 Appdelegate.m 文件中。

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

NSUInteger orientations = UIInterfaceOrientationMaskAllButUpsideDown;

if(self.window.rootViewController){
UIViewController *presentedViewController = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presentedViewController supportedInterfaceOrientations];
}

return orientations;
}

然后在我要锁定横屏的viewcontroller.m文件中加入下面的方法

- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskLandscape;
}

关于ios - Xcode IOS Lock 某些方向为纵向,某些方向为横向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27236752/

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