iOS 11:UICollectionView:出现时发生滚动 [英] iOS 11: UICollectionView: when appearing, scrolling happens

查看:34
本文介绍了iOS 11:UICollectionView:出现时发生滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的UIViewController出现并带有UICollectionView时,出现时内容会向上滚动一点.

我实现了 scrollViewDidScroll:,并且正在记录 contentOffset.y :

  -20.000000-20.0000000.0000000.000000 

这仅在iOS 11(模拟器和设备)上发生,而不在iOS 10或iOS 9上发生.

EDIT (非常奇怪):这仅在未调用viewDidLoad时发生,例如当UIViewController已经存在并再次弹出时,但第一次显示该UIViewController时不弹出...

解决方案

在iOS 11中,可以在UIScrollView和子类(UICollectionView,UITableView)中添加contentInset.top,同时在视图层次结构中显示状态栏,navigationBar或其他内容.

此插图来自新的AdjustedContentInset属性.(文档: adjustedContentInset )

要删除此额外的插图,请将scrollView上的内容插图调整设置为从不:

[self.myScrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

WWDC17视频中的更多信息:为iOS 11更新您的应用距19'

when my UIViewController appears with a UICollectionView inside, the content scrolls up a little bit, when appearing.

I implemented scrollViewDidScroll: and I'm logging the contentOffset.y:

-20.000000
-20.000000
0.000000
0.000000

This only happens on iOS 11 (simulator and device), not on iOS 10 or iOS 9. Anyone else experiencing this?

EDIT VERY WEIRD thing: this only happens when viewDidLoad is NOT called, so e.g. when the UIViewController already exists and it is popped onto again, but not when first showing that UIViewController...

解决方案

In iOS 11, contentInset.top can be added in UIScrollView and subclasses (UICollectionView, UITableView) while status bar, navigationBar or other content appear in your view hierarchy.

This inset come from new adjustedContentInset property. (doc : adjustedContentInset)

To remove this extra inset, set content inset adjustment on your scrollView to never :

[self.myScrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

More info in the WWDC17 video : Updating Your App for iOS 11 at 19'

这篇关于iOS 11:UICollectionView:出现时发生滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆