您好,登录后才能下订单哦!
主要原理是根据,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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。