gpt4 book ai didi

ios - ios5中的自动旋转——失败的最常见原因?

转载 作者:行者123 更新时间:2023-12-01 19:21:40 25 4
gpt4 key购买 nike

我对 ios 中自动旋转的实现感到困惑。
我有一个 UIViewController,我告诉它在 shouldAutoRotateToInterfaceOrientation 内部自动旋转。但是,它不起作用。
所以我读了一些关于我需要如何查看导航堆栈和/或是否使用了 UITabBarController 的内容,因为众所周知这会导致各种困惑(举手)。

事实上,我有一个 UITabBar 和一个 UINavigationController。我要旋转的 UIView 被插入堆栈三或四个“级别”深。

为什么自动旋转不完全由当前 UIViewController 中的 shouldAutoRotateToInterfaceOrientation 返回的内容决定?

来自苹果的技术文档,位于:https://developer.apple.com/library/ios/#qa/qa2010/qa1688.html关于为什么 UIViewController 在您期望它时可能不会旋转:

All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set.



为了确保您的所有 subview Controller 正确旋转,
你必须为每个实现 shouldAutorotateToInterfaceOrientation
表示每个选项卡或导航级别的 View Controller 。每个必须
同意旋转发生的相同方向。也就是说,他们
对于相同的方向位置,所有都应该返回 YES。

有人可以总结一下我们在使用 UITabBars 和 UINavigationControllers 时需要注意的事实吗?人们通常在哪里搞砸,或者什么是困惑点?

如果您有一个 UITabBar、UITabBarController 或 UINavigationController,它的所有 subview 都需要具有相同的自动旋转行为。但是你肯定可以让一些 subview 旋转而其他 subview 不旋转,对吧?

我怀疑失败的常见原因与对响应链的理解不够好有关,因为它适用于自转。如果是这样,有人可以帮我解决这个问题吗?然后我也许能够弄清楚“选择性自转”。

除此之外,其他帖子表明您必须继承 UITabBarController 并覆盖 shouldAutorotateToInterfaceOrientation。

最佳答案

我认为您希望他们都以相同的方式响应的原因是因为这对用户来说很尴尬。如果您在可以旋转的特殊 View 上处于横向模式,当您将该 View Controller 弹出到导航 Controller 上的父级或点击没有横向模式的选项卡时,这将是一种奇怪的体验。

我认为这就是其中的原因。

但是,如果需要,您可以捕获设备方向通知并自行处理它们,如果设备在您要旋转的特定 View 上旋转,则可以推送新 View 。

用这个:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(rotationDetected) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

然后创建一个函数 rotationDetected它处理我们旋转时发生的事情......像这样:
-(void) rotationDetected {

if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)){

//Push on the view in landscape orientation if we aren't there already

} else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) {

//If the landscape view is present, pop it back to the portait view

}

关于ios - ios5中的自动旋转——失败的最常见原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10131869/

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