我想在集合视图和表视图的内容视图的底部添加一个视图(因此适用于任何类型的滚动视图),我也希望能够向下滚动以查看此视图例如:
- (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);
}
然而,这会导致各种显示问题。
答案 0 :(得分:0)
如果我理解正确,你想在底部的tableView(f.e.)中显示加载视图。您可以将包含此LoaderView的额外UITableViewCell添加到tableView。 (必须更改numberOfRowsInTableView)
在scrollViews的另一个视角中:使用较小的边界,然后使用内容本身,以使其可滚动。例如frame = fullscreen。在子视图中添加或修改每个单元格(添加)contentSize =内容大小+ 30 px。
答案 1 :(得分:0)
尝试创建滚动视图的子类并覆盖contentSize getter,以便总是返回30 px。
- (CGSize)contentSize {
CGSize customContentSize = super.contentSize;
customContentSize.height += 30;
return customContentSize;
}
(我是按内存编写代码,可能有错误)