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

时间:2014-09-09 20:52:56

标签: ios cocoa-touch uicollectionview ios8 uiinterfaceorientation

在Xcode 6 Beta 7及其之前的所有版本中,我有一个集合视图,当iPad在横向和纵向之间旋转时,它会更新其单元格的约束。现在,它根本没有更新,事实上它看起来就像我把它留在XIB中一样,这对我来说意味着它根本没有更新。看来我正在使用的可重用视图正确更新,但单元格肯定不是。

还有其他人遇到过此问题吗?任何人对如何克服它有什么想法?

我正在使用iOS 7.1模拟器。

4 个答案:

答案 0 :(得分:28)

您需要创建UICollectionViewCell的子类,并将该子类作为所有单元格的超类。

示例:

@interface MDTCollectionViewCell : UICollectionViewCell
@end

@implementation MDTCollectionViewCell

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

@end

答案 1 :(得分:3)

覆盖自定义单元格layoutSubviews作为临时修复:

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

答案 2 :(得分:0)

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

答案 3 :(得分:0)

在我的 UICollectionViewCell 类中我添加了

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

我使用此代码刷新

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