iOS 8 GM does not update constraints on collection

2019-03-24 14:45发布

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. 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. 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.

4条回答
相关推荐>>
2楼-- · 2019-03-24 15:00

The workaround I have come up with is to use the 8.0 simulator for testing in the sim, and build the deployable using Xcode Beta 7. When I build using Beta 7, the app runs without this issue on devices using iOS 7. However, this does not help anyone that is deploying to the app store, so I apologize if this workaround does not work for your situation.

查看更多
Explosion°爆炸
3楼-- · 2019-03-24 15:04

You need to make a subclass of UICollectionViewCell and make that subclass as the superclass of ALL of your cells.

Example:

@interface MDTCollectionViewCell : UICollectionViewCell
@end

@implementation MDTCollectionViewCell

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

@end
查看更多
太酷不给撩
4楼-- · 2019-03-24 15:06

Override the custom cell's layoutSubviews as a temporary fix:

override func layoutSubviews() {
    contentView.frame = bounds
    super.layoutSubviews()
}
查看更多
Luminary・发光体
5楼-- · 2019-03-24 15:21

in my UICollectionViewCell class I added

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()
})
查看更多
登录 后发表回答