Objective c 切换到横向视图并使用选项卡栏控制器

Objective c 切换到横向视图并使用选项卡栏控制器,objective-c,ios,xcode,views,Objective C,Ios,Xcode,Views,我正在为我的应用程序使用选项卡栏控制器。如果我在一个名为“结果”的视图控制器中,并且ios设备旋转到横向模式,它将切换到我创建的另一个名为横向的视图。这是在方法中完成的 -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration { [super willRotateToInterfaceOrientat

我正在为我的应用程序使用选项卡栏控制器。如果我在一个名为“结果”的视图控制器中,并且ios设备旋转到横向模式,它将切换到我创建的另一个名为横向的视图。这是在方法中完成的

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight ||
        toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.view=landScape;
    } else {
        self.view=originalView;
    }
}
只要我在选项卡栏中的特定控制器(示例结果视图控制器)中,它就可以正常工作。然而;如果我转到选项卡栏控制器中的另一个元素,我的手机在横向模式下倾斜,然后我决定转到resultsviewcontroller,它不会调用我的视图横向,而是尝试自动调整视图大小,这看起来很糟糕。我应该调用方法-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)到InterfaceOrientation duration:(NSTimeInterval)duration在我的viewDidLoad方法中解决问题吗?还是这完全错了


提前谢谢你

问题是,只有当它是活动视图控制器并检测到旋转时,才设置
resultsViewController.view
。试试这个:

- (void)setViewForInterfaceOrientation:(UIInterfaceOrientation)orientation
{
    self.view = UIInterfaceOrientationIsPortrait(orientation)
        ? originalView
        : landScape;
}

- (void)viewWillAppear
{
    [self setViewForInterfaceOrientation:[[UIDevice currentDevice] orientation];
    [super viewWillAppear];
}

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrient‌​ation duration:(NSTimeInterval)duration
{
    [self setViewForInterfaceOrientation:toInterfaceOrientation];
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}

谢谢你的回复,罗布。我就是这样做的,你觉得怎么样?-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)to interfaceOrientation duration:(NSTimeInterval)duration{[超级willRotateToInterfaceOrientation:to interfaceOrientation:duration];如果(toInterfaceOrientation==UIInterfaceOrientationAndscapeRight | | toInterfaceOrientation==UIInterfaceOrientationAndscapeLeft){self.view=横向;}否则{self.view=originalView;}把它放在你的…对不起,我是新来的this@marcus13您可以添加自己的答案,甚至可以添加到您自己的问题(如果有意义的话)我已经根据您当前的实现更改了我的答案。