ios - 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)

希望有帮助!

https://stackoverflow.com/questions/952412/

相关文章:

ios - cocoa touch : How To Change UIView's Border

iphone - 开发一个 iPhone 应用程序需要多少钱?

objective-c - block 声明语法列表

ios - 退出 iPhone 应用程序的正确方法?

ios - Objective-C 中的字符串替换

ios - 如何向 UIView 添加触摸事件?

objective-c - iOS7 无法隐藏状态栏

ios - UIActivityViewController 在 iOS 8 iPad 上崩溃

objective-c - #pragma 标记的意义​​是什么?为什么我们需要#pragma 标记

ios - 如何在 NSUserDefaults 中存储自定义对象