ios - UIScrollView 以编程方式滚动到底部

标签 ios objective-c swift uiscrollview

如何使 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/

相关文章:

ios - 是否可以将工具栏添加到 UIAlertController,以及使用 Swift 将按钮添加到行?

ios - 如何以编程方式点击 ios google map 标记或显示标记的信息窗口?

ios - 使用 JSQMessage 下载后难以让媒体替换占位符

swift - 什么替换了 init(name :float:) now that it has been deprecated

objective-c - 混合 CAGradientLayer 用作阴影

ios - 如何通过 FMDB 将数据保存和检索到 sqlite

ios - 我们可以在 Swift Playground 中添加过渡动画吗?

ios - 使用 3D 坐标的 SCNShape

ios - 循环核心数据关系

ios - NSTimer 毫秒精度