IOS学习——视图坐标


1、frame与bounds属性
首先还是先看一下源码跟一张官方提供图片
-(CGRect)frame{
    return CGRectMake(self.frame.origin.x,self.frame.origin.y,self.frame.size.width,self.frame.size.height);
}
-(CGRect)bounds{
    return CGRectMake(0,0,self.frame.size.width,self.frame.size.height);
}





从图中和代码中不难发现,frame 主要是针对父视图中的位置,而bounds是针对自己的,两哲都有origin 跟size属性,size属性两者都一样,都是定义了视图的宽 高, origin属性,对于bounds来说永远是(0,0)因为参照物是自己,对于frame来说,相对于父视图进行参照


1、contentOffSize 与contentOffset 属性

contentOffSize 是scrollView的一个属性,代码scrollView中可显示的区域,

contentOffset 是scrollView当前显示区域顶点相对于frame顶点的偏移量,假如scrollView的frame为(0,0,320,480) contentSzie为(320,960)那拉到最下面时contentOffset为(0,320)

contentInset是scrollView中contentView.frame.orgin与scrollView.frame.orgin的关系,比如contentView的frame为(0,30,320,480)那么contentInset则为(0,30);

猜你喜欢

转载自fanfanlovey.iteye.com/blog/1906701