iOS 8 GM does not update constraints on collection views

时光总嘲笑我的痴心妄想 提交于 2019-12-03 11:52:06
Sean Freitag

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

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

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

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.

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()
})
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!