gpt4 book ai didi

ios - 如何检测 iOS View Controller 的当前方向?

转载 作者:行者123 更新时间:2023-11-29 05:57:14 25 4
gpt4 key购买 nike

在我的应用程序中,根据 View Controller 手动设置方向。除了这个 View Controller 之外,我还需要检测最顶层 View Controller 的当前方向(不是设备方向)。可能吗?

这就是我设置方向的方式。

-(BOOL)shouldAutorotate {
return YES;
}

-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}

最佳答案

如上所述,您想要检查根/最顶层 VC 中设置的当前方向。

因此您可以使用以下代码进行检测:-

if (topViewController.responds(to: Selector(("canRotate")))) else{
// view is set to portrait
return .portrait;
}
// // view is set to landscape
return .allButUpsideDown;

关于ios - 如何检测 iOS View Controller 的当前方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55037418/

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