自动旋转在iOS 7中无法正常工作,在iOS 6中运行良好

时间:2022-06-23 11:02:28

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.

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

So heres my issue :

所以继承我的问题:

  1. start app and load initial nav controller with view controller that only supports portrait
  2. 使用仅支持纵向的视图控制器启动应用程序并加载初始导航控制器

  3. push view controller on to stack that supports landscape AND portrait
  4. 将视图控制器推送到支持横向和纵向的堆栈

  5. rotate view to landscape
  6. 将视图旋转到横向

  7. pop view controller
  8. 流行视图控制器

  9. 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

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

In my AppDelegate I implement the following method :

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

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

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

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

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

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:

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

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

不知道已经在iOS的7改变了关于这一点,因为所有工作正常,在IOS 6看来,在搭载iOS 7的应用程序无法自动旋转回来一次横向视图被弹出。

Any help would be appreciated..

任何帮助,将不胜感激..

2 个解决方案

#1


14  

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

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

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,

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

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

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

In the Category. M writes

在类别中。 M写道

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

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

#2


1  

You can simple use this:--

你可以简单地使用它: -

-(void)rotateCameraView
{
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
}

//Mohit 18 Oct
- (void)deviceOrientationDidChange:(NSNotification *)notification {
    //Obtaining the current device orientation
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    //Ignoring specific orientations
    if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationUnknown) {
        return;
    }

    if ((UIDeviceOrientationIsPortrait(orientation) ||UIDeviceOrientationIsPortrait(orientation)) ||
    (UIDeviceOrientationIsLandscape(orientation) || UIDeviceOrientationIsLandscape(orientation))) {
        //still saving the current orientation
        currentOrientation = orientation;
    }
    [self performSelector:@selector(orientationChangedMethod) withObject:nil afterDelay:0];
}

//Mohit 18 Oct
    -(void)orientationChangedMethod
    {
        switch (currentOrientation) {

            case UIDeviceOrientationPortrait:
       }
    }


//Note here current orientation is a UIDeviceOrientation currentOrientation; global variable.

#1


14  

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

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

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,

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

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

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

In the Category. M writes

在类别中。 M写道

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

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

#2


1  

You can simple use this:--

你可以简单地使用它: -

-(void)rotateCameraView
{
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil];
}

//Mohit 18 Oct
- (void)deviceOrientationDidChange:(NSNotification *)notification {
    //Obtaining the current device orientation
    UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

    //Ignoring specific orientations
    if (orientation == UIDeviceOrientationFaceUp || orientation == UIDeviceOrientationFaceDown || orientation == UIDeviceOrientationUnknown) {
        return;
    }

    if ((UIDeviceOrientationIsPortrait(orientation) ||UIDeviceOrientationIsPortrait(orientation)) ||
    (UIDeviceOrientationIsLandscape(orientation) || UIDeviceOrientationIsLandscape(orientation))) {
        //still saving the current orientation
        currentOrientation = orientation;
    }
    [self performSelector:@selector(orientationChangedMethod) withObject:nil afterDelay:0];
}

//Mohit 18 Oct
    -(void)orientationChangedMethod
    {
        switch (currentOrientation) {

            case UIDeviceOrientationPortrait:
       }
    }


//Note here current orientation is a UIDeviceOrientation currentOrientation; global variable.