标签:object c table bsp hang options nts get contents float
#pragma mark - KVO
- (void)p_registerObserve {
if (_myCollectionView) {
[_myCollectionView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:kCollectionViewContentSizeContext];
}
}
- (void)p_deregisterObserve {
// 这里不使用点语法触发懒加载,因为可能在这里才触发懒加载创建collectionView,此时还没有添加观察者
// 如果这时移除观察者很可能会造成崩溃
if (_myCollectionView) {
[_myCollectionView removeObserver:self forKeyPath:@"contentSize" context:kCollectionViewContentSizeContext];
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
if (context == kCollectionViewContentSizeContext) {
CGSize contentSize = [change[NSKeyValueChangeNewKey] CGSizeValue];
CGFloat width = GET_SCREEN_WIDTH-(isPad?82:0);
self.myCollectionView.frame = CGRectMake(0, 0, width, contentSize.height);
self.baseTableView.tableFooterView = self.myCollectionView;
}
}
标签:object c table bsp hang options nts get contents float
原文地址:http://www.cnblogs.com/1018475062qq/p/7016742.html