美文网首页
contentSize 、contentOffset、conte

contentSize 、contentOffset、conte

作者: json_jie | 来源:发表于2016-05-30 15:24 被阅读65次

contentSize 是UIScrollView和他的子类的可以 滚动的区域
contentOffset 是UIScrollView和他的子类的可以 相对于坐标原点(一般来说是左上角的点)的偏移量
contentInset 是contentView相对于UIScrollView的顶点位置

做累死与微博效果 下拉的时候头部的放大效果
对这三个的属性的的分辨 尤其是contentInset属性的分辨出现错误

QQ20160530-0@2x.png QQ20160530-1@2x.png

<p>

忘记抄自哪里的代码了 下边这是核心代码

<p>

 static CGFloat kImageOriginHight = 200;
    -(UITableView *)tableView{
      if (_tableView == nil){
          _tableView= [[UITableView   alloc]initWithFrame:CGRectMake(0,0,ScreenWidth,ScreenHeight)];
          _tableView.delegate=self;
          _tableView.dataSource=self;
          _tableView.backgroundColor= [UIColor lightGrayColor];
          _tableView.contentInset=UIEdgeInsetsMake(kImageOriginHight,0,0,0);
      }
       return _tableView;
    }  
-(ETCPPersonCenterHeadTableViewCell *)headView{
  ETCPPersonCenterHeadTableViewCell *cellView = [[[NSBundle mainBundle]loadNibNamed:@"ETCPPersonCenterHeadTableViewCell" owner:self options:nil]firstObject];
  cellView.frame=CGRectMake(0, -kImageOriginHight,ScreenWidth,kImageOriginHight);
  cellView.delegate = self;
  return cellView;
}

- (void)scrollViewDidScroll:(UIScrollView*)scrollView{
  CGFloat yOffset  = scrollView.contentOffset.y;
  CGFloat xOffset = (yOffset +kImageOriginHight)/2;
  if(yOffset < -kImageOriginHight) {
      CGRect f = _headImageView.frame;
      f.origin.y = yOffset ;
      f.size.height =  -yOffset;
      f.origin.x = xOffset;
      f.size.width = ScreenWidth + fabs(xOffset)*2;
      _headImageView.frame = f;
    [_headImageView updateConstraints];
  }
}

  _headImageView = [self headView];
  [self.view addSubview:[self tableView]];
  [self.tableView addSubview: _headImageView];

相关文章

网友评论

      本文标题:contentSize 、contentOffset、conte

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