2017-10-18 82 views
1

我有一个简单的UICollectionView,其中包含navigationController中的自定义单元格。出于某种原因,当我推送一个viewController时,collectionView单元在转换过程中改变其布局。swift:uicollectionview在转换过程中更改单元格的内容偏移量

在viewController转换过程中它是uicollectionview的一些常见行为吗?因为,例如:标签不具有这样的问题

When back button was clicked 从的CollectionView

绿色添加新的视图控制器

navigationController?.pushViewController(controller, animated: true) 

使用EasyPeasy

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

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

您有任何代码可以告诉我们吗? –

+0

很难理解你想用这些约束来做什么,但是你没有为collectionview使用任何高度。我认为这是按钮计算的。因为它看起来绿色collectionview被设置为10px(也许?)..你什么时候在你的代码中设置约束?那个蓝色盒子和那个元素的限制是什么?感觉像你的自动布局有一些问题无论如何.. –

+0

@MartinBorstrand UICollectionViewCell的backgroundColor是蓝色的。我在viewDidLoad中设置了约束。对不起给您带来不便。看起来像在转换回单元格变得更小 – Dauren

回答

0

我自动布局设置认为我发现了你的问题,它在你的AppDelegate中。对您的导航控制器设置为false的属性isTranslucent似乎成了这个罕见的问题。半透明的导航栏将位于视图控制器的视图之上,如上图所示。一个非半透明的导航栏会压下你的视图控制器的视图,换句话说就是将它重新整理,以便它适合它。但是,为什么collectionview的动画就像它一样,实际上我不能给出明确的答案。也许别人可以做到这一点?..

为了让你的导航栏半透明,你可以在viewcontroller中设置'extendedLayoutIncluedsOpaqueBars'为true的另一个属性。

所以..这样做。在你的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 

然后,在您的视图控制器viewDidLoad方法中加入这一行

extendedLayoutIncludesOpaqueBars = true 

希望这将解决您的问题! :)

Apple Documentation about extendedLayoutIncludesOpaqueBars

+0

@Dauren你会对我的回答作出反应吗? –

相关问题