Ios 旋转和调整大小后UITableView和UITableViewHeader冲突

Ios 旋转和调整大小后UITableView和UITableViewHeader冲突,ios,objective-c,uitableview,rotation,frame,Ios,Objective C,Uitableview,Rotation,Frame,我有一个带有tableview标题(而不是节标题)的tableview,这两个标题都可以根据方向调整大小。在我的实现中,我正在ViewWillLayoutSubView中为两个视图设置框架 我现在的问题是,虽然两个视图在旋转后分别正确地调整大小,但tableView的原点并没有改变以考虑页眉的高度变化。这会导致它们之间出现一个空格,或者页眉覆盖一些单元格 我的目标是在纵向,桌面视图屏幕宽度与长标题。当旋转到横向时,宽度减小到屏幕宽度的三分之一,右对齐,标题较短。同样,我需要旋转动画,使所有这些更

我有一个带有tableview标题(而不是节标题)的tableview,这两个标题都可以根据方向调整大小。在我的实现中,我正在ViewWillLayoutSubView中为两个视图设置框架

我现在的问题是,虽然两个视图在旋转后分别正确地调整大小,但tableView的原点并没有改变以考虑页眉的高度变化。这会导致它们之间出现一个空格,或者页眉覆盖一些单元格

我的目标是在纵向,桌面视图屏幕宽度与长标题。当旋转到横向时,宽度减小到屏幕宽度的三分之一,右对齐,标题较短。同样,我需要旋转动画,使所有这些更改平滑且符合逻辑


我对iOS轮换和动画练习相当生疏,所以如果有人有更好的建议,我一定会非常感激。

在您重新分配tableHeader之前,Table view不会考虑新的页眉高度

类似问题:

旋转将完成或完成时,您可以执行以下操作:

- (void)didRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    self.tableView.tableHeaderView = self.tableView.tableHeaderView;
}
事实上,这里也是计算收割台高度的地方:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    CGRect frame = self.tableView.tableHeaderView.frame;
    frame.size.height = UIInterfaceOrientationIsLandscape(toInterfaceOrientation) ? 50 : 150;
    self.tableView.tableHeaderView.frame = frame;

    self.tableView.tableHeaderView = self.tableView.tableHeaderView;
}

在iOS 8.0+上,您可以呼叫:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator;

嗨,重新分配头球是我错过的。在设置了标题的框架之后,我使用self.tableView.tableHeaderView调用了setTableHeaderView。现在一切看起来都很好。非常感谢。第一个代码示例中的方法签名应该是
-didRotateFromInterfaceOrientation:
,而不是
-didrotateInterfaceOrientation:duration:
 override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {

    coordinator.animate(alongsideTransition: { (UIViewControllerTransitionCoordinatorContext) in



        self.tableView.tableHeaderView? = YourTableHeaderView()

    }, completion: { (UIViewControllerTransitionCoordinatorContext) in



    })

    super.viewWillTransition(to: size, with: coordinator)
}