Scrollview

UIScrollView继承UIView,它有两个子类,分别是UITableView和UITextView。UIScrollView有三个容易让人混淆的属性变量:

1、contentSize: scrollview可显示的区域


属性类型:

struct CGSize {

    CGFloat width;

    CGFloat height;

};

typedef struct CGSize CGSize;

[objc]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. @property(nonatomic) CGSize contentSize  
  2. Description The size of the content view.  
  3. Availability    iOS (2.0 and later)  
  4. Declared In UIScrollView.h  
  5. Reference   UIScrollView Class Reference  
假如一个scrollview的frame为(0,0,320,480),而它的contentSize为(320,960).也就是说,这个scrollview整个内容的大小为(320,960),要通过上下滑动scrollview来查看(320,480)后的内容。

2、contentOffset: scrollview当前显示区域顶点相对于frame顶点的偏移量

属性类型:

struct CGPoint {

    CGFloat x;

    CGFloat y;

};

typedef struct CGPoint CGPoint;

[objc]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. @property(nonatomic) CGPoint contentOffset  
  2. Description The point at which the origin of the content view is offset from the origin of the scroll view.  
  3. Availability    iOS (2.0 and later)  
  4. Declared In UIScrollView.h  
  5. Reference   UIScrollView Class Reference  

经过测试发现:CGFloat offsetY = scrollView.contentOffset.y;

当scrollview向下拉时,offsetY为负数;当上拉时,offsetY不断增大,当越过原点后会变成正数。

比如上个例子你拉到最下面,contentoffset就是(0 ,480),也就是y偏移了480

3、contentInset: scrollview的contentview的顶点相对于scrollview的位置

属性类型:

typedef struct UIEdgeInsets {

    CGFloat top, left, bottom, right;

} UIEdgeInsets;

[objc]  view plain  copy
 
  在CODE上查看代码片 派生到我的代码片
  1. @property(nonatomic) UIEdgeInsets contentInset  
  2. Description The distance that the content view is inset from the enclosing scroll view.  
  3. Availability    iOS (2.0 and later)  
  4. Declared In UIScrollView.h  
  5. Reference   UIScrollView Class Reference  

它有点类似css中的padding。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值