如何使 UIScrollView
在我的代码中滚动到底部?或者以更通用的方式,到 subview 的任何一点?
最佳答案
您可以使用 UIScrollView 的 setContentOffset:animated:
函数滚动到内容 View 的任何部分。假设您的 scrollView 是 self.scrollView
,下面是一些会滚动到底部的代码:
objective-C :
CGPoint bottomOffset = CGPointMake(0, self.scrollView.contentSize.height - self.scrollView.bounds.size.height + self.scrollView.contentInset.bottom);
[self.scrollView setContentOffset:bottomOffset animated:YES];
swift :
let bottomOffset = CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.height + scrollView.contentInset.bottom)
scrollView.setContentOffset(bottomOffset, animated: true)
希望有帮助!
关于ios - UIScrollView 以编程方式滚动到底部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/952412/