简体   繁体   English

迅速:uicollectionview在过渡期间更改单元格的contentoffset

[英]swift: uicollectionview changes contentoffset of the cell during transition

I have a simple UICollectionView with a custom cell inside of a navigationController. 我有一个简单的UICollectionView,带有一个NavigationController内的自定义单元格。 For some reason when I push a viewController, the collectionView cell changes its layout during the transition. 由于某些原因,当我按下viewController时,collectionView单元会在过渡期间更改其布局。

Is it some common behavior of uicollectionview during viewController transition? 这是viewController过渡期间uicollectionview的一些常见行为吗? Because, for example: labels don't have such problem 因为,例如:标签没有这样的问题

When back button was clicked Green color from collectionView 单击后退按钮时 ,collectionView中的绿色

Adding new view controller 添加新的视图控制器

navigationController?.pushViewController(controller, animated: true)

Setting Autolayout using EasyPeasy pod 使用EasyPeasy Pod设置自动布局

collectionView.easy.layout([
  Top(),
  Right(),
  Width(view.frame.width),
  Bottom(10).to(button),
])

button.easy.layout([
  Center(),
  Height(60),
  Width(300),
])

I think I've found your problem and it's in you AppDelegate. 我想我已经找到了您的问题,它在您的AppDelegate中。 The property isTranslucent which is set to false to your navigation controller seems to cauese this rare problem. 为您的导航控制器设置为false的属性isTranslucent似乎解决了这一罕见问题。 A translucent navigation bar will be on top of your viewcontroller's view, like above it. 像上面一样,半透明的导航栏将位于视图控制器视图的顶部。 A non-translucent navigation bar pushes down your view controller's view or in other words rezising it so it fits beneath it.. But why the collectionview animates like it does is something I actually cant give a definite answer about. 一个不透明的导航栏会向下推您的视图控制器的视图,或者换句话说,将其缩放以使其适合其下方。.但是为什么collectionview会像它那样动画,这实际上是我无法给出确切答案的。 Maybe someone else could do that?.. 也许其他人可以做到?

To keep your navigation bar translucent you can set another property in your viewcontroller which is ´extendedLayoutIncluedsOpaqueBars´ to true. 为了使导航栏保持透明,可以在视图控制器中将另一个属性“ extendedLayoutIncluedsOpaqueBars”设置为true。

So.. Do like this. 所以..这样做。 In your AppDelegate: 在您的AppDelegate中:

window = UIWindow(frame: UIScreen.main.bounds)
window!.makeKeyAndVisible()
let controller = TestingNavigationController()
let navigation = UINavigationController(rootViewController: controller)
window!.rootViewController = navigation

let navigationBarAppereance = UINavigationBar.appearance()
navigationBarAppereance.isTranslucent = false

Then, in your view controllers viewDidLoad method add this line 然后,在视图控制器的viewDidLoad方法中添加以下行

extendedLayoutIncludesOpaqueBars = true

Hope this will solve your problem! 希望这能解决您的问题! :) :)

Apple Documentation about extendedLayoutIncludesOpaqueBars Apple关于ExtendedLayoutIncludesOpaqueBars的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM