Layout 在iOS中调用方法调整布局的最佳位置

Layout 在iOS中调用方法调整布局的最佳位置,layout,ios7,orientation,landscape,portrait,Layout,Ios7,Orientation,Landscape,Portrait,从纵向切换到横向时,我在修改布局时遇到问题。布局如下所示。如您所见,开关需要重新定位两个浅灰色内部面板。视图控制器嵌入在导航控制器中,面板包含按钮,这些按钮可触发进一步的视图控制器 所有的大小调整都由AutoLayout很好地完成,但是重新定位需要使用CGRect。屏幕上的旋转由 - (void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(

从纵向切换到横向时,我在修改布局时遇到问题。布局如下所示。如您所见,开关需要重新定位两个浅灰色内部面板。视图控制器嵌入在导航控制器中,面板包含按钮,这些按钮可触发进一步的视图控制器

所有的大小调整都由AutoLayout很好地完成,但是重新定位需要使用CGRect。屏幕上的旋转由

- (void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIInterfaceOrientationIsPortrait(toInterfaceOrientation)) {
        self.topImagePanel.frame = CGRectMake(44, 16, 196, 392);
        self.bottomImagePanel.frame = CGRectMake(44, 407, 196, 392);
    } else {
        self.topImagePanel.frame = CGRectMake(72, 64, 196, 392);
        self.bottomImagePanel.frame = CGRectMake(268, 64, 196, 392);
    }
}
下面的方法处理启动和导航回主屏幕

- (void) adjustLayoutToOrientation
{
    UIInterfaceOrientation deviceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    if (UIDeviceOrientationIsLandscape(deviceOrientation)){
        self.topImagePanel.frame = CGRectMake(72, 64, 196, 392);
        self.bottomImagePanel.frame = CGRectMake(268, 64, 196, 392);
    } else if (UIDeviceOrientationIsPortrait(deviceOrientation)) {
        self.topImagePanel.frame = CGRectMake(44, 16, 196, 392);
        self.bottomImagePanel.frame = CGRectMake(44, 407, 196, 392);
    }
}
调用此方法最有效的地方似乎是ViewDidEmbeen。问题在于,每当视图以横向模式出现时。它首先出现在故事板中的布局中,也就是说,在被正确的布局替换之前,在一段短暂的时间间隔内以纵向模式出现

我尝试过从ViewWillDisplay调用,但尽管调用了该方法,但横向布局从未出现。我也尝试过从viewDidLayoutSubviews调用。横向布局在返回时显示,虽然不是在启动时,但具有与上述相同的故障。我还尝试过一件事,就是对不同的布局使用不同的视图控制器,但这似乎真的太过了,导致的问题比解决的问题还多。谢谢你的帮助