您好,登錄后才能下訂單哦!
主要原理是根據,UITableView 的 contentOffset 的偏移量計算頭部 tableHeaderView 中的 UIImageView 的高度,并實時改變
// iOS 9 之前的API - (void)willMoveToSuperview:(UIView *)newSuperview
- (void)willMoveToSuperview:(nullable UIView *)newSuperview
{
[super willMoveToSuperview:newSuperview];
_scrollView = (UIScrollView *)newSuperview;
_imgView.frame = CGRectMake(0, 0, newSuperview.bounds.size.width, self.frame.size.height);
[_scrollView addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
[_scrollView addObserver:self forKeyPath:@"contentInset" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}
// iOS 9 之前的API - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
{
if (object == _scrollView) {
NSLog(@"TableHeadScaleView %f", _scrollView.contentOffset.y);
if ([keyPath isEqualToString:@"contentOffset"]) {
if (_scrollView.contentOffset.y < 0) {
_imgView.frame = CGRectMake(0, _scrollView.contentOffset.y, _imgView.bounds.size.width, 90+ABS(_scrollView.contentOffset.y));
}
}else if ([keyPath isEqualToString:@"contentInset"]) {
}
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。