gpt4 book ai didi

ios - 执行 -layoutSubviews 后仍然需要自动布局。 UICollectionView的-layoutSubviews的实现需要调用super

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:14:14 25 4
gpt4 key购买 nike

我使用 UICollectionView默认 UICollectionViewFlowLayout .它适用于 iOS 8,但在 iOS 7.1 上我得到

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Auto Layout still required after executing -layoutSubviews. UICollectionView's implementation of -layoutSubviews needs to call super

我找到了这个 “Auto Layout still required after executing -layoutSubviews” with UITableViewCell subclass但没有一个解决方案有效

另一个线索是我在 UICollectionView 中添加了一些 View ,并为该 View 设置了 AutoLayout

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[self.collectionView addSubview:button];

[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.equalTo(self.collectionView);
make.height.mas_equalTo(30);
}];

这是我的自定义 UICollectionView 中的内容

@implementation FTGCollectionView

- (void)layoutSubviews {
[super layoutSubviews];
//[self layoutIfNeeded]; // Should not call as it cause collection view to not scroll
}

@end

最佳答案

我认为是iOS 7的bug,不是[self.collectionView addSubview:button];我改成[self.view addSubview:button];, self.view 是 self.collectionView 的父 View 。

所以在 iOS7 中不要将 subview 添加到 UICollectionView 并为该 subview 使用自动布局

关于ios - 执行 -layoutSubviews 后仍然需要自动布局。 UICollectionView的-layoutSubviews的实现需要调用super,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32063004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com