自动旋转在iOS 7中无法正常工作,在iOS 6中运行良好 [英] Autorotation not working in iOS 7 , works fine in iOS 6

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

问题描述

我有一个仅在某些部分支持横向的应用程序(照片库,视频等),并且所有功能在iOS 6上运行正常,没有任何问题,但是,在iOS 7中应用程序崩溃。



所以继承我的问题:


  1. 启动app并加载初始导航控制器查看仅支持肖像的控制器

  2. 将视图控制器推送到支持横向和纵向的堆栈

  3. 将视图旋转到横向

  4. pop view controller

  5. app crashes




   - > 
CRASH:** preferredInterfaceOrientationForPresentation必须返回支持的界面方向!**
2013-11-06 10:18:06.220 ausopen-iphone-2014 [57605:70b] Stack Trace:(
0 CoreFoundation 0x03f665e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x03ce38b6 objc_exception_throw + 44
2 CoreFoundation 0x03f663bb + [NSException raise:format:] + 139
3 UIKit 0x01366f1c - [UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation :]

+ 580


其他信息:



在我的info.plist中,我支持肖像和风景



在我的AppDelegate中,我实现了以下方法:

   - (NSUInteger)应用程序:(UIApplication *)应用程序supportedInterfaceOrientationsForWindow:(UIWindow *)window {} 

在此方法中,我指定如果第一个视图(HomeVC)显示它应该支持所有方向。



在这个方法中,我还指定如果第二个视图(PhotoVC)显示它也应该支持所有方向。



在我的第一个视图(HomeVC)中,我使用以下方法覆盖此方法,以便在显示视图时仅支持纵向模式:

   - (BOOL)shouldAutorotate {
返回YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
返回UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
返回UIInterfaceOrientationMaskPortrait;
}

不确定iOS 7中有什么变化,因为一切正常在iOS 7中很好。看起来在iOS 7中,一旦弹出横向视图,应用程序就不会自动旋转。



任何帮助都将受到赞赏..

解决方案

在IOS7中。如果使用UINavigationController,则旋转处理方式不同!



看到UINavigationController,可以看到它是UIViewController的子类,那就是在他上面列出了上面的旋转处理方法;所以我需要使用UINavigationController也做旋转处理,



我的方法是将类别添加到UINavigationController,这样做。



在类别中。 M写道

   - (BOOL)shouldAutorotate {
return [[self.viewControllers lastObject] shouldAutorotate];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}


I have an app that supports landscape orientation only on some sections (Photo gallery, video, etc) and all is working fine on iOS 6 with no issues, however, in iOS 7 the app crashes.

So heres my issue :

  1. start app and load initial nav controller with view controller that only supports portrait
  2. push view controller on to stack that supports landscape AND portrait
  3. rotate view to landscape
  4. pop view controller
  5. app crashes

-->
CRASH: **preferredInterfaceOrientationForPresentation must return a supported interface orientation!**
2013-11-06 10:18:06.220 ausopen-iphone-2014[57605:70b] Stack Trace: (
  0   CoreFoundation                      0x03f665e4 __exceptionPreprocess + 180
  1   libobjc.A.dylib                     0x03ce38b6 objc_exception_throw + 44
  2   CoreFoundation                      0x03f663bb +[NSException raise:format:] + 139
  3   UIKit                               0x01366f1c -[UIViewController _preferredInterfaceOrientationForPresentationInWindow:fromInterfaceOrientation:]

+ 580

Other info :

In my info.plist i support portrait and landscape

In my AppDelegate I implement the following method :

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

In this method I specify that if the first view (HomeVC) is showing that it should support ALL orientations.

In this method I also specify that if the second view (PhotoVC) is showing that it should also support ALL orientations.

In my first view (HomeVC) i override this method with the following methods so that only portrait mode is supported when the view is showing:

- (BOOL)shouldAutorotate {
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
} 

Not sure what has changed in iOS 7 in regards to this because all is working fine in iOS 6. It seems that in iOS 7 the app is not auto rotating back once the landscape view is popped.

Any help would be appreciated..

解决方案

In IOS7.If you use a UINavigationController, the rotate processing way is different!

See UINavigationController, can see it is a subclass of UIViewController, then that is in him there are listed in the above the rotation of the processing method; So wo need to use UINavigationController also do rotate processing,

My way is to add a Category to UINavigationController, do so.

In the Category. M writes

-(BOOL)shouldAutorotate {    
  return [[self.viewControllers lastObject] shouldAutorotate];
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {    
  return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation]; 
}

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

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