UIScrollView的常用属性

来源:互联网 发布:a站mac 编辑:程序博客网 时间:2024/06/09 22:41

UIScrollView常用属性-contentSize

  • scrollView 要滚动就必须设置了滚动视图的 contentSize
  • contentSize 的 width 决定了水平方向滚动距离
  • contentSize 的 height 决定了垂直方向滚动距离

UIScrollView常用属性-contentOffset

  • scrollView 通过修改 contentOffset 调整内部视图的坐标位置,从而给用户产生一种视觉上的滚动的效果
  • contentOffset 的值本质上就是 bounds 的原点(origin) 值,苹果在为了方便程序员的理解,增加了这个属性
  • 文档释义:contentOffset:内容视图原点(origin)所在的偏移位置,相对于 scroll view 的 origin,默认是 CGPointZero

UIScrollView常用属性-contentOffset-两个方法

 // 以恒定速度动画移动到新的 offset -(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; // animate at constant velocity to new offset // 滚动到可见区域(靠近边缘-不会滚动到边缘外侧),如果当前区域完全可见,则什么也不做 -(void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated; // scroll so rect is just visible (nearest edges). nothing if rect completely visible

UIScrollView常用属性-contentInset

  • scrollView 通过修改 contentInset 调整内部和边缘的偏移
  • 设置边距之后,初始没有效果,需要拖拽一下才有效果
    可以通过设置 contentOffset 调整初始位置
0 0