美文网首页
TableView上滑或者下滑实现头视图或者尾视图方法缩小

TableView上滑或者下滑实现头视图或者尾视图方法缩小

作者: 吞风吻雨葬落日未曾彷徨 | 来源:发表于2016-05-18 14:51 被阅读43次
    • 将需要的imageView实现下面的两个属性
      声明一个UIImageView *footImageView
      再声明一个背景UIView *backgroundView
      声明一个属性 CGRect initalFrame 代替 footImageView的frame
      声明一个属性 CGFloat defaultViewHigh 作为 footImageView的高度
      因为tableview只有View放在头视图或者尾视图才起作用。
    self.footImageView.contentMode = UIViewContentModeScaleToFill;
    self.footImageView.clipsToBounds = YES;
      _initalFrame = _footImageView.frame;
      _defaultViewHight = _initalFrame.size.height;
    
    - (void)scrollViewDidScroll:(UIScrollView*)scrollView {
        scrollView.backgroundColor = [self replaceStringToUIColor:self.carouselModel.bgcolor];
    // 滑动的总区域
        CGFloat ht = scrollView.contentSize.height  - self.tableView.frame.size.height; 
        if (scrollView.contentOffset.y >= ht) {
            CGFloat offsetY = scrollView.contentOffset.y - ht;
            _initalFrame.origin.y = screenHeight - 200 + 50 + 15 + offsetY/1.5; // footView在背景视图的高度
            _initalFrame.origin.x =  -offsetY / 2;
            _initalFrame.size.width = screenWidth  + offsetY;
            _initalFrame.size.height = 200 + offsetY / 1.5;
            _footImageView.frame = _initalFrame;
        }
    }
    

    相关文章

      网友评论

          本文标题:TableView上滑或者下滑实现头视图或者尾视图方法缩小

          本文链接:https://www.haomeiwen.com/subject/imdwrttx.html