方向更改期间iOS大小调整UITableView

方向更改期间iOS大小调整UITableView,ios,uitableview,Ios,Uitableview,我有一个视图,它有两个表。在故事板中,我有两个独立的视图,一个是水平视图,另一个是垂直视图。当我需要导航到视图时,代码会检测方向并显示相应的视图(并在方向更改时显示) 我的方法中有以下代码: -(void)viewDidAppear:(BOOL)animated{ UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation; if(orientation =

我有一个视图,它有两个表。在故事板中,我有两个独立的视图,一个是水平视图,另一个是垂直视图。当我需要导航到视图时,代码会检测方向并显示相应的视图(并在方向更改时显示)

我的方法中有以下代码:

-(void)viewDidAppear:(BOOL)animated{
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if(orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight){
    if(tableHeight2 > 324){
        tableHeight2 =325;
    }
    table1.frame = CGRectMake(table1.frame.origin.x, table1.frame.origin.y, table1.frame.size.width, tableHeight1);
    table2.frame = CGRectMake(table2.frame.origin.x, table1.frame.origin.y + 20 + tableHeight1, table2.frame.size.width, tableHeight2);
}else {
    if(tableHeight2 > 500){
        tableHeight2 = 500;
    }
    table1.frame = CGRectMake(table1.frame.origin.x, table1.frame.origin.y, table1.frame.size.width, tableHeight1);
    table2.frame = CGRectMake(table2.frame.origin.x, table1.frame.origin.y + 50 + tableHeight1, table2.frame.size.width, tableHeight2);
}
}

当我按下一个按钮导航到视图时,这种方法非常有效。它将所有单元格高度相加,使第一个表格具有适当的高度,然后将第二个表格移动到第一个表格下方50像素的位置。它还确保第二个表格不会超出可见屏幕区域

当方向改变时,执行以下代码:

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

    InitViewController *ini;
    ini = [self.storyboard instantiateViewControllerWithIdentifier:@"Init"];
    ini.location = MenuName;
    [self presentViewController:ini animated:NO completion:nil];
}
这应该与按下按钮按钮所做的事情相同:在ini.location变量中向其发送故事板ID时更改为InitViewController。导航按钮的代码与WillAnimateRotationInterfaceOrientation中的代码几乎相同。InitViewController然后确定方向并发送应用到正确的情节提要UIView

它确实会将其发送到正确的视图,我可以根据表格宽度来判断。它不会更改第一个(顶部)表格的高度,即表格1。第一个表格保留了故事板中给出的大小

如果您认为我需要发布一些代码以获得更好的图片,请告诉我,我很乐意添加。任何帮助、见解,甚至只是尝试和错误建议都将不胜感激


*注意:我试图将WillAnimateRotationInterfaceOrientation更改为ViewDidLayoutSubviews,但没有效果。

好吧,这似乎是一个很小的更改。我注意到导航按钮上的代码在“动画”下的“是”表示视图更改,而WillAnimateRotationInterfaceOrientation“动画:否”。我将其更改为“是”这就解决了这个问题。我还不确定为什么,也许它会影响方法显示视图的方式,或者影响加载顺序,但它确实存在