UIScrollView按偏移量滚动 [英] UIScrollView scroll by offset
本文介绍了UIScrollView按偏移量滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这种情况:
- 一个适合所有屏幕的scrollView
- scrollView中的N个单元格",每个单元格都包含一个标签
- 每个单元格的高度为80px
- 固定的绿色蒙版(UIView)
我以编程方式创建带有标签的单元格(UIView),并正确设置了scrollView的contentSize.
I programmatically create the cells (UIView) with label inside and correctly set contentSize of scrollView.
我知道
scrollView.setContentOffset(CGPoint(x: 0, y: 80.0), animated: true)
将滚动视图移动80.
如何才能覆盖"滚动视图行为以始终滚动80? 我想要的是某种选择器行为..这可能吗?
How can I "override" scroll view behaviour in order to always scroll by 80? What i want is sort of picker behaviour.. is this possible?
推荐答案
当布局更改时,可以使用以下方法
You can use the following method when your layout changes
func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
myScrollView.contentOffset.y += 80
}
这篇关于UIScrollView按偏移量滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文