【发布时间】:2017-08-24 22:54:40
【问题描述】:
我正在尝试让 UIScrollView 向上滚动而不是向下滚动。我已经设置了所有内容,但我不知道应该使用哪条线来完成此操作。我该怎么办?
尼尔
【问题讨论】:
我正在尝试让 UIScrollView 向上滚动而不是向下滚动。我已经设置了所有内容,但我不知道应该使用哪条线来完成此操作。我该怎么办?
尼尔
【问题讨论】:
我认为你的意思是你想要一个从底部开始的scrollView,并且你的内容可以通过向上滚动来访问。
在这种情况下,您只需要弄清楚您的内容有多大,并将您的scrollView 的setContentOffset 设置为您的内容的高度:
override func viewDidLoad() {
// other code here...
// set the contentSize of the scrollView somewhere in here...
// get the offset based on the size of the content
let bottomOffset = CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.size.height)
// do not animate because we want to immediately scroll to the bottom
scrollView.setContentOffset(bottomOffset, animated: false)
此代码改编自this answer。
【讨论】: