我使用的是Xcode 5。
出于某种原因,如果我将图像视图放入集合视图单元格,我会收到以下警告
2013-11-20 06:21:39.987 Interface Builder Cocoa Touch Tool[1237:303]
WARNING:
Reason: Could not find layout engine view for view's (<UIView: 0x102939b0; frame = (-20 -20; 90 90); autoresize = RM+BM; layer = <CALayer: 0x10288690>>) coordinate space view <UIView: 0x1028aaf0; frame = (0 0; 50 50); autoresize = W+H; gestureRecognizers = <NSArray: 0x10298620>; layer = <CALayer: 0x10299730>>. But the canvas coordinateSpaceView is view's superview, so we are assuming the same in the layout engine.
File: /SourceCache/IBAutolayoutFoundationIOS/IBAutolayoutFoundation-3430/Framework/Classes/Arbitration/IBAutolayoutEngine.m:335
Method: -[IBAutolayoutEngine layoutFrameForView:inCoordinateSpaceOfView:]
这些警告污染了编译输出,有时我会错过重要的消息。
我怎样才能摆脱它?
以下是我的故事板片段,它导致:
<collectionView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" restorationIdentifier="zzzzz" minimumZoomScale="0.0" maximumZoomScale="0.0" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="esr-tl-gXA">
<rect key="frame" x="80" y="104" width="160" height="207"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<collectionViewFlowLayout key="collectionViewLayout" minimumLineSpacing="10" minimumInteritemSpacing="10" id="dJb-8s-18M">
<size key="itemSize" width="50" height="50"/>
<size key="headerReferenceSize" width="0.0" height="0.0"/>
<size key="footerReferenceSize" width="0.0" height="0.0"/>
<inset key="sectionInset" minX="0.0" minY="0.0" maxX="0.0" maxY="0.0"/>
</collectionViewFlowLayout>
<cells>
<collectionViewCell opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" id="A9w-gO-BzK">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<view key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="55Z-yW-7Qm">
<rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
</imageView>
</subviews>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
</view>
</collectionViewCell>
</cells>
</collectionView>
我已经为这个问题挣扎了一段时间(遇到类似的ibtool错误和异常),并尝试了以下所有方法:
- 检查了其中报告视图具有"错误"关系的所有XIB文件。还按照ibtool异常信息中的建议分析了console.app中的崩溃报告。我的布局没有什么问题
- 已删除包含UICollectionViewCell和UICollectionView的XIB文件。然后在Xcode5中从头开始重新创建它们
- 清洁+重建
- 重新启动Xcode,重新启动iOS模拟器
- 删除了Xcode:~/Applications/Xcode和~/Library/Developer/Xcode,然后重新编录最新的Xcode,并重新启动机器
- 将项目迁移到情节提要(即用一个情节提要替换了几乎所有的XIB文件。这个工具做了很多工作)
即使在迁移到Storyboard后,偶尔也会出现同样的错误,但我发现以下方法解决了这个问题:
- 重置iOS模拟器(iOS模拟器>重置内容和设置)
- 清理Xcode项目,然后重新启动Xcode
- 重新启动iOS模拟器
这当然是一个苹果,我已经和他们一起养大了。