UISCrollView相关知识点

1、UISCrollView不能滑动的原因


2、UISCrollView实现原理

UISCrollView实际上是通过拖拽手势的水平或者竖直方向上的位移从而改变scrollView的bounds的x或者y坐标,从而达到子视图出现偏移的情况,因为子视图的坐标是不变的,而父视图的bounds发生变化会导致子视图相对位置发生变化,从而产生滑动效果,contentoffset的x等于scrollView的bounds的x,y等于scrollView的bounds的y。contentInset的top决定了scrollView的bounds的y的最小值,从而决定了contentOffsetY的最小值。(在bounces为NO的情况下)


bounces为NO

subView.height+contentInset.top+contentInset.bottom <= scrollView.frame.size.height

的情况下,bounds的MinY =bounds的MaxY=scrollView的contentOffsetY = -contentInset.top;

subView.height+contentInset.top+contentInset.bottom > scrollView.frame.size.height

的情况下

bounds的MinY = scrollView的contentOffsetY =  - contentInset.top。bounds的MaxY = scrollView的contentOffsetY = contentInset.top+subView.height > = scrollView.frame.size.height ? subView.height - scrollView.frame.size.height +contentInset.bottom :(contentInset.bottom - (scrollView.frame.size.height - subView.height - contentInset.top)) -contentInset.top;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。