Xcode 带导航返回按钮的自动旋转

Xcode 带导航返回按钮的自动旋转,xcode,ipad,uinavigationcontroller,orientation,Xcode,Ipad,Uinavigationcontroller,Orientation,我正在创建一个支持所有方向的应用程序。 我正在使用navigationController。 对于方向,我使用此代码 - (void)willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { if (interfaceOrientation == UIInterfaceOrientationPortrait

我正在创建一个支持所有方向的应用程序。
我正在使用navigationController。
对于方向,我使用此代码

- (void)willAnimateRotationToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {

if (interfaceOrientation == UIInterfaceOrientationPortrait 
    || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
    category1.frame = CGRectMake(54, 68, 190, 174);
    category2.frame = CGRectMake(291, 68, 190, 174);
    category3.frame = CGRectMake(525, 68, 190, 174);
    category4.frame = CGRectMake(54, 296, 190, 174);
    category5.frame = CGRectMake(291, 296, 190, 174);
    category6.frame = CGRectMake(525, 296, 190, 174);
    category7.frame = CGRectMake(54, 527, 190, 174);
    category8.frame = CGRectMake(291, 527, 190, 174);
    category9.frame = CGRectMake(525, 527, 190, 174);
    category10.frame = CGRectMake(291, 757, 190, 174);
    extra1.frame = CGRectMake(80, 781, 138, 125);
    extra2.frame = CGRectMake(551, 781, 138, 125);

}
else 
{
    category1.frame = CGRectMake(61, 50, 190, 174);
    category2.frame = CGRectMake(298, 50, 190, 174);
    category3.frame = CGRectMake(537, 50, 190, 174);
    category4.frame = CGRectMake(774, 50, 190, 174);
    category5.frame = CGRectMake(61, 278, 190, 174);
    category6.frame = CGRectMake(298, 278, 190, 174);
    category7.frame = CGRectMake(537, 278, 190, 174);
    category8.frame = CGRectMake(774, 278, 190, 174);
    category9.frame = CGRectMake(298, 509, 190, 174);
    category10.frame = CGRectMake(537, 509, 190, 174);
    extra1.frame = CGRectMake(80, 533, 120, 125);
    extra2.frame = CGRectMake(800, 533, 120, 125);

}

}
从这个角度来看,它非常有效。当我按下tab按钮时,它会转到secondviewcontroller,我在这里显示tableview。
但是,如果我通过导航返回按钮返回firstview,则方向显示不完美。
以上代码不适用于导航返回按钮

我该怎么解决这个问题??
有什么建议吗

先谢谢你

编辑:

我已经从firstview中删除了上述函数,并将代码复制到此函数

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
    if (interfaceOrientation == UIInterfaceOrientationPortrait 
    || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
    category1.frame = CGRectMake(54, 68, 190, 174);
    category2.frame = CGRectMake(291, 68, 190, 174);
    category3.frame = CGRectMake(525, 68, 190, 174);
    category4.frame = CGRectMake(54, 296, 190, 174);
    category5.frame = CGRectMake(291, 296, 190, 174);
    category6.frame = CGRectMake(525, 296, 190, 174);
    category7.frame = CGRectMake(54, 527, 190, 174);
    category8.frame = CGRectMake(291, 527, 190, 174);
    category9.frame = CGRectMake(525, 527, 190, 174);
    category10.frame = CGRectMake(291, 757, 190, 174);
    extra1.frame = CGRectMake(80, 781, 138, 125);
    extra2.frame = CGRectMake(551, 781, 138, 125);

}
else 
{
    category1.frame = CGRectMake(61, 50, 190, 174);
    category2.frame = CGRectMake(298, 50, 190, 174);
    category3.frame = CGRectMake(537, 50, 190, 174);
    category4.frame = CGRectMake(774, 50, 190, 174);
    category5.frame = CGRectMake(61, 278, 190, 174);
    category6.frame = CGRectMake(298, 278, 190, 174);
    category7.frame = CGRectMake(537, 278, 190, 174);
    category8.frame = CGRectMake(774, 278, 190, 174);
    category9.frame = CGRectMake(298, 509, 190, 174);
    category10.frame = CGRectMake(537, 509, 190, 174);
    extra1.frame = CGRectMake(80, 533, 120, 125);
    extra2.frame = CGRectMake(800, 533, 120, 125);

}

    return YES;
 }
在我的第二个视图控制器中,我已经完成了

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {

    return YES;
 }

当我通过点击导航返回按钮返回firstview时,else条件(横向模式)可以正常工作,但我不知道为什么它不能与if条件(纵向模式)一起工作。

在以下函数中编写所有代码

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
 {
        //set all the frames according to the current interface orientation
        return YES;
 }
新编辑:

将此方法写入detailviewcontroller.m文件

  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
        UIViewController *controller = [self.navigationController.viewControllers objectAtIndex:0];
        [controller shouldAutorotateToInterfaceOrientation:interfaceOrientation];

        return YES;
  }

那么它应该会起作用。当您返回到此viewController时,它正在响应此方法,对吗?从该viewController的nib关闭自动调整子视图大小。此解决方案仅适用于横向模式。。知道为什么吗?这必须适用于所有方向。你一定是把相框设置错了。检查它们是否放置正确,并尝试调试此方法。用我建议的方法贴出你是怎么做的。我自己也试过了。工作正常。只需在“纵向”部分保留一个断点,并在其中打印nslogs,以了解发生了什么。