ios5-中的自动旋转-为什么它失败的最常见原因? [英] Autorotation in ios5--most common reasons why it fails?

查看:114
本文介绍了ios5-中的自动旋转-为什么它失败的最常见原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm confused about the implementation of autorotation in ios.
I have a UIViewController, and I tell it to autorotate inside shouldAutoRotateToInterfaceOrientation. However, it doesn't work. So I read something about how I need to look at the navigation stack AND/OR whether a UITabBarController was used, because this has been known to cause all kinds of confusion (raises hand).

实际上,我有一个UITabBar和一个UINavigationController.我想旋转的UIView被推入堆栈三到四个级别"深.

In fact, I have a UITabBar and a UINavigationController. The UIView that I want to rotate is being pushed onto the stack three or four 'levels' deep.

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

Why isn't autorotation solely determined by whatever the shouldAutoRotateToInterfaceOrientation returns inside the current UIViewController?

摘自位于以下位置的Apple技术文档: https://developer. apple.com/library/ios/#qa/qa2010/qa1688.html 关于为什么UIViewController可能在您希望旋转时可能不旋转的原因:

From apple's technical doc located at: https://developer.apple.com/library/ios/#qa/qa2010/qa1688.html about why a UIViewController may not be rotating when you expect it to:

您的UITabBarController或UINavigationController中的所有子视图控制器都无法在一个共同的方向集上达成共识.

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

为确保所有子视图控制器正确旋转, 您必须为每个实现shouldAutorotateToInterfaceOrientation 代表每个标签或导航级别的视图控制器.每个必须 同意发生旋转的相同方向.也就是说,他们 相同方向的位置都应返回YES.

To make sure that all your child view controllers rotate correctly, you must implement shouldAutorotateToInterfaceOrientation for each view controller representing each tab or navigation level. Each must agree on the same orientation for that rotate to occur. That is, they all should return YES for the same orientation positions.

有人可以总结在使用UITabBars和UINavigationControllers时需要注意哪些事实吗?人们通常在哪里弄糟,或有什么不解之处?

Can someone summarize what facts we need to be aware of when working with UITabBars and UINavigationControllers? Where do people commonly mess up or what are points of muddiness?

如果具有UITabBar,UITabBarController或UINavigationController,则其所有子视图都必须具有相同的自动旋转行为.但是可以肯定,您可以让某些子视图旋转,而另一些则不旋转,对吗?

If you have a UITabBar, UITabBarController, or UINavigationController, all of its child views need to have the same autorotation behavior. But surely you can have some child views rotate and others not rotate, right?

我怀疑失败的常见原因与对自动旋转适用的响应链不够了解有关.如果是这样,有人可以帮我解决这个问题吗?然后,我也许就能弄清楚选择性自动旋转".

I suspect that common reasons for failing have to do with not understanding the responder chain well enough as it applies to autorotation. If so, can someone clear this up for me? Then I might be able to figure out 'selective autorotation'.

要添加此内容,其他文章指出您必须子类化UITabBarController并覆盖shouldAutorotateToInterfaceOrientation.

To add to this, other posts indicate that you must subclass UITabBarController and override shouldAutorotateToInterfaceOrientation.

推荐答案

我认为您希望他们所有人都以相同的方式做出响应的原因是因为它会使用户感到尴尬.如果您在可以旋转的特殊视图上处于横向模式,那么当您将该视图控制器弹出到导航控制器上的父级或点击没有横向模式的选项卡时,这将是一种奇怪的体验.

I think the reason you want them all to respond the same way is because it gets awkward for the user. If you are in landscape mode on your special view that can rotate, it will be a strange experience when you pop that viewcontroller to the parent on the navigationcontroller or tap a tab that does not have landscape mode.

我认为那是原因.

但是,您可以捕获设备方向通知并根据需要自行处理,如果设备在要旋转的特定视图上旋转,则可以推入新视图.

However, you can catch the device orientation notifications and handle them yourself if you want and push in a new view if the device rotates on the particular view you want to rotate.

使用此:

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

然后创建一个函数rotationDetected,该函数处理我们旋转时发生的情况,如下所示:

then create a function rotationDetected that handles what happens when we rotate...like this:

-(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  

}

这篇关于ios5-中的自动旋转-为什么它失败的最常见原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆