Jas*_*Liu 4 objective-c ios11 xcode9
我添加了一种使滚动视图滚动到其顶部的方法。这在iOS10中按预期工作。但是,当我使用Xcode 9升级到iOS11时,它无法正常工作。是否有iOS11缺少的任何内容。
下面的代码正在工作:
[self setContentOffset:CGPointZero animated:YES];
Run Code Online (Sandbox Code Playgroud)
小智 8
你所要做的
self.view.layoutIfNeeded()
Run Code Online (Sandbox Code Playgroud)
在setContentOffset之前。它更新UIScrollView的contentSize,然后contentOffset可用。
尝试这个
dispatch_async(dispatch_get_main_queue(), ^{
[UIView animateWithDuration:.25 animations:^{
[self setContentOffset:CGPointZero animated:YES];
}];
});
Run Code Online (Sandbox Code Playgroud)
小智 6
为滚动视图设置estimatedRowHeight = 0、estimatedSectionHeaderHeight = 0、estimatedSectionFooterHeight = 0 解决了这个问题。每当内容偏移量发生变化时,UIKit 会计算每个部分的行、页眉和页脚的高度以滚动到新的偏移量。EstimatedRowHeight、estimatedSectionHeaderHeight、estimatedSectionFooterHeight 默认为 -1
(SWIFT 4) 我有一个类似的问题,问题是动画:true。因此,您可以尝试通过手动执行以下操作:
view.layoutIfNeeded()
UIView.animate(withDuration: 0.2) {
self.scroll.setContentOffset(.zero, animated: false)
}
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你。它为我固定
| 归档时间: |
|
| 查看次数: |
6236 次 |
| 最近记录: |