在iOS 7中手动管理UITableView的contentInset的正确方法是什么?

时间:2014-02-14 20:31:47

标签: objective-c uitableview ios7 uiscrollview uiedgeinsets

我在单个视图控制器中嵌入了两个单独的全屏容器视图中的UITableViewController,并在它们之间切换了一个分段控制栏按钮项(就像在App Store的顶部图表中一样)。由于视图控制器中有两个滚动视图,因此我必须手动管理它们的插入(如类引用中所述)。在具有自动旋转的iOS 7中执行此操作的正确方法是什么?

这就是我现在所拥有的,在我的UITableViewController子类实现中:

- (void)viewWillAppear:(BOOL)animated
{
    portraitEdgeInsets = UIEdgeInsetsMake(64.0, 0.0, 44.0, 0.0);
    landscapeEdgeInsets = UIEdgeInsetsMake(52.0, 0.0, 32.0, 0.0);

    [_fileTable setScrollIndicatorInsets:portraitEdgeInsets];
    [_fileTable setContentInset:portraitEdgeInsets];
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (toInterfaceOrientation == UIDeviceOrientationPortrait) {
        [_fileTable setScrollIndicatorInsets:portraitEdgeInsets];
        [_fileTable setContentInset:portraitEdgeInsets];
    }
    else {
        [_fileTable setScrollIndicatorInsets:landscapeEdgeInsets];
        [_fileTable setContentInset:landscapeEdgeInsets];
    }
}

它几乎可以工作,但是如果在旋转到纵向之前将表视图一直滚动到横向模式的顶部,由于前一个插入,它将向下滚动12个像素(插入是正确的;表视图只是不会一直滚动到顶部)。我注意到,对于自动插入的表视图,会发生相反的情况:如果它们一直滚动到横向底部,则返回到纵向时将从底部向上滚动12个像素。那不是问题。我只是想让两个表视图都像自动插入一样。

0 个答案:

没有答案