在iOS 6中无法自动旋转 [英] Can't auto rotate in iOS 6

查看:160
本文介绍了在iOS 6中无法自动旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个应用程序,我保持有一个旋转,应该发生在纵向和肖像下降模式。 (在汇总面板中启用所有旋转。)

   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
//对于支持的方向返回YES
return interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown;
}

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

无论我尝试过我无法获得旋转6



我尝试过的东西:

   - NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}

- (NSInteger)supportedInterfaceOrientations {
NSInteger mask = 0;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight])
mask | = UIInterfaceOrientationMaskLandscapeRight;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeLeft])
mask | = UIInterfaceOrientationMaskLandscapeLeft;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortrait])
mask | = UIInterfaceOrientationMaskPortrait;
if([self shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationPortraitUpsideDown])
mask | = UIInterfaceOrientationMaskPortraitUpsideDown;
return mask;
}

我试过将其放在我的appdelegate中:



- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortraitUpsideDown;
}

但我收到此错误:由于未捕获异常终止应用程序'UIApplicationInvalidInterfaceOrientation ',原因:'支持的方向与应用程序没有共同的方向,并且shouldAutorotate正在返回YES'



尝试将其放入我的委托:

   - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{
NSUInteger orientationations = UIInterfaceOrientationMaskAll;

if(self.window.rootViewController){
UIViewController * presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientationations = [present supportedInterfaceOrientations];
}
return orientation;
}

我读了所有关于它的讨论以及shouldAutorotateToInterfaceOrientation的弃用,



我即将失去它

解决方案

从苹果的iOS 6 SDK发行说明


自动旋转在iOS 6中改变。 6,不推荐使用 UIViewController shouldAutorotateToInterfaceOrientation:方法。在其位置,您应该使用 supportedInterfaceOrientationsForWindow: shouldAutorotate 方法。



更多的职责是移动到应用程序和应用程序委托。现在,iOS容器(如 UINavigationController )不咨询他们的孩子,以确定他们是否应该自动旋转。默认情况下,应用程序和视图控制器支持的界面方向设置为 UIInterfaceOrientationMaskAll (对于iPad成语)和 UIInterfaceOrientationMaskAllButUpsideDown



视图控制器支持的界面方向可以随时间变化,即使应用程序支持的界面方向也可能随时间变化。每当设备旋转时或每当视图控制器呈现全屏模态呈现样式时,系统询问最上面的全屏视图控制器(通常是根视图控制器)的支持的接口定向。此外,仅当此视图控制器从其 shouldAutorotate 方法返回 YES 时,才检索支持的方向。系统将视图控制器支持的方向与应用程序支持的方向(由Info.plist文件或应用程序委托的应用程序:supportedInterfaceOrientationsForWindow:方法确定)相交,以确定是否旋转。



系统通过将应用程序的supportedInterfaceOrientationsForWindow:方法返回的值与最顶层全屏方法的supportedInterfaceOrientations方法返回的值相交,来确定是否支持方向:屏幕控制器。 setStatusBarOrientation:animated:方法不会被弃用。它现在仅在最顶层全屏视图控制器的supportedInterfaceOrientations方法返回0时才起作用。这使得调用者负责确保状态栏方向一致。



为了兼容性,仍然实现 shouldAutorotateToInterfaceOrientation:方法的视图控制器不会获得新的自动旋转行为。 (换句话说,它们不会使用应用程序,应用程序代理或Info.plist文件来确定支持的方向。)而是 shouldAutorotateToInterfaceOrientation:方法用于合成 supportedInterfaceOrientations 方法返回的信息。


如果你想让你的整个应用程序旋转,那么你应该设置你的Info.plist支持所有的方向。现在如果你想要一个特定的视图只是纵向,你将不得不做一些子类,并重写自动旋转方法只返回纵向。只需查看如何在iOS 6中将UIViewController强制为Portait方向


In an app i'm maintaining there's a rotate that should happen in portrait and portraitupsidedown mode. (all the rotation are enabled in the summary panel.)

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

or

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

No matter what I tried I couldn't get the rotate to accure i ios 6

Things I've tried so far:

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait; 
}

-(NSInteger)supportedInterfaceOrientations{
NSInteger mask = 0;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight])
    mask |= UIInterfaceOrientationMaskLandscapeRight;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft])
    mask |= UIInterfaceOrientationMaskLandscapeLeft;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait])
    mask |= UIInterfaceOrientationMaskPortrait;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown])
    mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
return mask;
}

I tried putting this in my appdelegate:

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskPortraitUpsideDown;
}

But I'm getting this error: Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

Tried putting this in my delegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    NSUInteger orientations = UIInterfaceOrientationMaskAll;

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

I read all the discussions about it and the deprecations of shouldAutorotateToInterfaceOrientation but i still can't get it to work.

I'm about to lose it

解决方案

From Apple's iOS 6 SDK Release Notes:

Autorotation is changing in iOS 6. In iOS 6, the shouldAutorotateToInterfaceOrientation: method of UIViewController is deprecated. In its place, you should use the supportedInterfaceOrientationsForWindow: and shouldAutorotate methods.

More responsibility is moving to the app and the app delegate. Now, iOS containers (such as UINavigationController) do not consult their children to determine whether they should autorotate. By default, an app and a view controller’s supported interface orientations are set to UIInterfaceOrientationMaskAll for the iPad idiom and UIInterfaceOrientationMaskAllButUpsideDown for the iPhone idiom.

A view controller’s supported interface orientations can change over time—even an app’s supported interface orientations can change over time. The system asks the top-most full-screen view controller (typically the root view controller) for its supported interface orientations whenever the device rotates or whenever a view controller is presented with the full-screen modal presentation style. Moreover, the supported orientations are retrieved only if this view controller returns YES from its shouldAutorotate method. The system intersects the view controller’s supported orientations with the app’s supported orientations (as determined by the Info.plist file or the app delegate’s application:supportedInterfaceOrientationsForWindow: method) to determine whether to rotate.

The system determines whether an orientation is supported by intersecting the value returned by the app’s supportedInterfaceOrientationsForWindow: method with the value returned by the supportedInterfaceOrientations method of the top-most full-screen controller. The setStatusBarOrientation:animated: method is not deprecated outright. It now works only if the supportedInterfaceOrientations method of the top-most full-screen view controller returns 0. This makes the caller responsible for ensuring that the status bar orientation is consistent.

For compatibility, view controllers that still implement the shouldAutorotateToInterfaceOrientation: method do not get the new autorotation behaviors. (In other words, they do not fall back to using the app, app delegate, or Info.plist file to determine the supported orientations.) Instead, the shouldAutorotateToInterfaceOrientation: method is used to synthesize the information that would be returned by the supportedInterfaceOrientations method.

If you want your whole app to rotate then you should set your Info.plist to support all orientations. Now if you want a specific view to be portrait only you will have to do some sort of subclass and override the autorotation methods to return portrait only. Just have a look at How to force a UIViewController to Portait orientation in iOS 6

这篇关于在iOS 6中无法自动旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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