我怎么能让一个UIScrollView滚动到我的代码底部?或者用更一般的方式,到子视图的任意点?
当前回答
我还发现了另一种有用的方法,在这种情况下,你正在使用UITableview(这是UIScrollView的子类):
[(UITableView *)self.view scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
其他回答
Xamarin的。iOS版本的UICollectionView的接受答案,便于复制和粘贴
var bottomOffset = new CGPoint (0, CollectionView.ContentSize.Height - CollectionView.Frame.Size.Height + CollectionView.ContentInset.Bottom);
CollectionView.SetContentOffset (bottomOffset, false);
我还发现了另一种有用的方法,在这种情况下,你正在使用UITableview(这是UIScrollView的子类):
[(UITableView *)self.view scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
如果你不需要动画,这是可行的:
[self.scrollView setContentOffset:CGPointMake(0, CGFLOAT_MAX) animated:NO];
如果contentSize低于边界怎么办?
对于Swift来说,它是:
scrollView.setContentOffset(CGPointMake(0, max(scrollView.contentSize.height - scrollView.bounds.size.height, 0) ), animated: true)
你可以使用UIScrollView的setContentOffset:animated:函数滚动到内容视图的任何部分。这里有一些代码可以滚动到底部,假设你的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];
迅速:
let bottomOffset = CGPoint(x: 0, y: scrollView.contentSize.height - scrollView.bounds.height + scrollView.contentInset.bottom)
scrollView.setContentOffset(bottomOffset, animated: true)
推荐文章
- 如果模态ViewController演示样式为UIModalPresentationFormSheet, iPad键盘将不会解散
- 在UITableView中检测哪个UIButton被按下了
- 为iOS模拟器构建,但链接框架'****.framework'是为iOS构建的
- iOS更新后保留旧的启动屏幕和应用程序图标
- 如何象征崩溃日志Xcode?
- 以编程方式更改导航标题
- 我如何得到一个plist作为一个字典在Swift?
- Xcode - ld:没有为- lpods找到库
- 自动调整掩码大小编程vs接口生成器/ xib / nib
- NSUserDefaults -如何判断一个键是否存在
- Xcode UI测试用例中的延迟/等待
- 如何在Swift中删除视图的所有子视图?
- 属性getter和setter
- 裁剪一个UIImage
- 为什么我需要在swift的下划线?