简体   繁体   English

iOS 8 GM不会更新集合视图的约束

[英]iOS 8 GM does not update constraints on collection views

In Xcode 6 Beta 7 and all versions before it, I had a collection view that would update its constraints on its cells when an iPad would rotate between landscape and portrait. 在Xcode 6 Beta 7和之前的所有版本中,我有一个集合视图,当iPad在横向和纵向之间旋转时,它会更新其单元格的约束。 Now, it doesn't update at all, and in fact it looks exactly like how I leave it in the XIB, which implies to me that it's not updating at all. 现在,它根本没有更新,事实上它看起来就像我将它留在XIB中一样,这对我来说意味着它根本没有更新。 It appears that the reusable views I'm using are updating correctly, but the cells certainly are not. 我正在使用的可重用视图似乎正在正确更新,但单元格当然不是。

Has anyone else run into this issue yet? 还有其他人遇到过这个问题吗? Anyone have any ideas for how to get past it? 任何人都有任何关于如何通过它的想法?

I'm using the iOS 7.1 simulator. 我正在使用iOS 7.1模拟器。

You need to make a subclass of UICollectionViewCell and make that subclass as the superclass of ALL of your cells. 您需要创建UICollectionViewCell的子类,并将该子类作为所有单元格的超类。

Example: 例:

@interface MDTCollectionViewCell : UICollectionViewCell
@end

@implementation MDTCollectionViewCell

- (void)setBounds:(CGRect)bounds {
    [super setBounds:bounds];
    self.contentView.frame = bounds;
}

@end

Override the custom cell's layoutSubviews as a temporary fix: 覆盖自定义单元格的layoutSubviews作为临时修复:

override func layoutSubviews() {
    contentView.frame = bounds
    super.layoutSubviews()
}

我提出的解决方法是使用8.0模拟器在sim中进行测试,并使用Xcode Beta 7构建可部署。当我使用Beta 7构建时,应用程序在使用iOS 7的设备上运行时没有此问题。但是,这对部署到应用程序商店的任何人都没有帮助,所以如果这种解决方法对您的情况不起作用,我会道歉。

in my UICollectionViewCell class I added 在我添加的UICollectionViewCell类中

override func layoutSubviews() {
    contentView.frame = bounds
    super.layoutSubviews()
}

and I used this code to refresh 我用这段代码刷新

dispatch_async(dispatch_get_main_queue(), { () -> Void in
    // in this case vController is UICollectionView
    self.vController.reloadData()
    self.vController.layoutSubviews()
})

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

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