在Ios7中处理特定ViewController的方向

在Ios7中处理特定ViewController的方向,ios,xcode,orientation,Ios,Xcode,Orientation,我正在创建一个电子书应用程序,其中我只为两个ViewController提供了所有方向 我第一次成功地设置了两个视图控制器的方向并执行了旋转。但是后来,当我用新书加载视图控制器时,旋转无法正常工作 我使用了以下方法: -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)

我正在创建一个电子书应用程序,其中我只为两个ViewController提供了所有方向

我第一次成功地设置了两个视图控制器的方向并执行了旋转。但是后来,当我用新书加载视图控制器时,旋转无法正常工作

我使用了以下方法:

  -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
                           duration:(NSTimeInterval)duration{
  if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight )    {
  //code for landscape
  }
  else{
   //code for protrait.
  }
  }

  - (BOOL)shouldAutorotate{
    return YES;
  } 
 - (NSUInteger)supportedInterfaceOrientations{
    return (UIInterfaceOrientationMaskAll);
 }

尝试处理UINavigationControllers上的旋转,UINavigationControllers子类上的确切代码是正确的。并确保将UIViewController设置为新UINavigationController的ChildViewController。
请记住,您需要使用info.plist上的键supported interface orientations设置支持的方向。

创建UINavigationController的子类

@接口BaseNavigationController:UINavigationController

@结束

在特定的viewController中:

#import "VideoVC.h"

@interface VideoVC ()

@end

@implementation VideoVC
#pragma mark- Methods for device orientation handling
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}
- (BOOL)shouldAutorotate
{
    return YES;
}

@end

您是否尝试在新的viewController中使用preferredInterfaceOrientationForPresentation?即设置支持的方向类型?您所说的-是什么意思?但稍后,当我用新书加载视图控制器时,旋转无法正常工作??你在重新加载页面吗,在层次结构中导航还是什么?大多数视图都超出了框架。请在稍后我用新书加载视图控制器时更具体地说明旋转不正常。我没有使用导航控制器。那么有没有办法在视图控制器中处理它?您可以使用上面的代码并在自定义中隐藏导航导航类。如何加载viewController?你在推它吗。。。。。?尝试呈现viewController并测试它,而不是将其推送到navigationController,我们应该只[self-presentViewController:vc animated:YES completion:nil];来自viewDidLoad?-IBActionpushVideoClicked:idsender{VideoVC*obj\U VideoVC=[[VideoVC alloc]initWithNibName:@VideoVC bundle:nil];/[self.navigationController pushViewController:obj\u VideoVC动画:YES];[self-presentViewController:obj\u VideoVC动画:YES完成:nil];}试试这个。。
#import "VideoVC.h"

@interface VideoVC ()

@end

@implementation VideoVC
#pragma mark- Methods for device orientation handling
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationLandscapeLeft;
}
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskLandscapeLeft;
}
- (BOOL)shouldAutorotate
{
    return YES;
}

@end