0

我想在集合视图和表格视图的内容视图底部添加一个视图(因此适用于任何类型的滚动视图),我还希望能够向下滚动以查看此视图​​,例如:

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Observe change in content size so can move my view when
        // content size changes (keep it at the bottom)
        [self addObserver:self forKeyPath:@"contentSize"
                  options:(NSKeyValueObservingOptionPrior)
                  context:nil];
        CGRect frame = CGRectMake(0, 0, 200, 30);
        self.loadingView = [[UIView alloc] initWithFrame:frame];
        [self.loadingView setBackgroundColor:[UIColor blackColor]];
        [self addSubview:self.loadingView];
        // Increase height of content view so that can scroll to my view.
        self.contentSize = CGSizeMake(self.contentSize.width, self.contentSize.height+30);

    }
    return self;
}

但是,例如,当插入一个单元格时,会重新计算 contentSize 并且虽然我的视图在内容大小的底部仍然可见(由于能够反弹滚动视图),但我无法再滚动到它。

如何确保内容大小保持在我的代码中高 30 点?

另一个问题是:

  • 除了观察之外,还有其他方法可以跟踪内容大小吗?

提前致谢。


我努力了:

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.contentSize = CGSizeMake(self.contentSize.width, self.contentSize.height+30);
}

但是,这会导致各种显示问题。

4

2 回答 2

0

如果我理解正确,您想在底部的 tableView (fe) 中显示加载视图。您可以将包含此 LoaderView 的额外 UITableViewCell 添加到 tableView。(必须更改 numberOfRowsInTableView)

在 scrollViews 的另一个角度:使用比内容本身更小的边界,使其可滚动。例如帧 = 全屏。在子视图中添加或修改的每个单元格(添加) contentSize = 内容大小 + 30 px。

于 2013-04-29T19:10:06.477 回答
0

尝试创建滚动视图的子类并覆盖 contentSize getter 以始终返回 30 px 以上。

- (CGSize)contentSize {
    CGSize customContentSize = super.contentSize;
    customContentSize.height += 30;
    return customContentSize;
}

(我是凭记忆写代码,可能有错误)

于 2013-04-29T19:23:11.300 回答