【发布时间】:2018-11-22 18:30:18
【问题描述】:
我有一个滚动视图,正在尝试以编程方式滚动到它的底部..
试过这些:
extension UIScrollView {
// Bonus: Scroll to bottom
func scrollToBottom() {
let bottomOffset = CGPoint(x: 0, y: contentSize.height - bounds.size.height + contentInset.bottom)
if(bottomOffset.y > 0) {
setContentOffset(bottomOffset, animated: true)
}
}
}
来自:
Programmatically scroll a UIScrollView to the top of a child UIView (subview) in Swift
let bottomOffset = CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.size.height)
scrollView.setContentOffset(bottomOffset, animated: true)
来自:
UIScrollView scroll to bottom programmatically
但两者都没有做任何事情......
怎么做?
【问题讨论】:
-
在主线程中试试
-
你在哪里调用这个方法?尝试拨打
viewDidAppear -
@karthikeyan 谢谢!
-
@LalKrishna 谢谢!
-
现在有什么效果了吗?