首页 > 其他 > 详细

UITableView头部的图片,下拉缩放

时间:2016-01-29 16:32:37      阅读:230      评论:0      收藏:0      [点我收藏+]

主要原理是根据,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"]) {
            
        }
    }
    
}

本文出自 “11036754” 博客,请务必保留此出处http://11046754.blog.51cto.com/11036754/1739824

UITableView头部的图片,下拉缩放

原文:http://11046754.blog.51cto.com/11036754/1739824

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!