我想添加一个视图到集合视图和表视图(因此适用于任何类型的滚动视图)的内容视图的底部,我也希望能够向下滚动以查看此视图,例如:UICollectionView等计算内容大小,以便我可以永久增加它?
- (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);
}
然而这会导致各种各样的显示问题。
你可能想在layoutSubviews做这些计算。 – atreat 2013-04-29 18:59:25
这是UICollectionView等通常计算contentSize的地方吗? – Michael 2013-04-29 19:00:23
我没有看到代码中的任何内容会改变您正确的“contentSize' – matt 2013-04-29 19:05:28