czl0325 / ZLCollectionView

为应对类似淘宝首页,京东首页,国美首页等复杂布局而写的Collectionview。基于UICollectionView实现,目前支持标签布局,列布局,百分比布局,定位布局,填充式布局,瀑布流布局等。支持纵向布局和横向布局,可以根据不同的section设置不同的布局,支持拖动cell,头部悬浮,设置section背景色和自定义section背景view,向自定义背景view传递自定义方法。功能强大,超过Android的recyclerview,实现了电影选座等高难度的布局。
MIT License
1.16k stars 166 forks source link

使用 NSLayoutConstraint 进行header拉伸的时候会崩溃 #49

Closed mayunhao910324 closed 1 year ago

mayunhao910324 commented 2 years ago

将header 中的 imageview 跟viewcontroller 中的view 进行绑定会崩溃

NSLayoutConstraint *layout = [self.backImage.topAnchor constraintEqualToAnchor:collectionView.topAnchor]; [NSLayoutConstraint activateConstraints:@[layout]];

但是使用普通的UICollectionViewFlowLayout 却没有问题

错误信息:

Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to activate constraint with anchors <NSLayoutYAxisAnchor:0x2814699c0 "UIImageView:0x10ac6f2a0.top"> and <NSLayoutYAxisAnchor:0x28144ad00 "UICollectionView:0x10c176c00.top"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'

czl0325 commented 2 years ago

绑定错了吧。你怎么会backImage和collectionView绑定呢?backImage的父容器是header不是collectionView把

mayunhao910324 commented 2 years ago

虽说两个父视图不一样 但是普通的layout 就没问题 很诧异