UICollectionViewLayoutを継承したLayaout実装して、UICollectionViewCellを継承したCellに情報を表示しています。最初は大丈夫なのですが、スクロールを繰り返すうちにAutoLayoutの制約エラーが出ます。
Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) ( "<NSLayoutConstraint:0x17469c750 UIImageView:0x1743e5e00.width == 1.33333*UIImageView:0x1743e5e00.height>", "<NSLayoutConstraint:0x17469c340 H:[UIImageView:0x1743e5e00]-(10)-| (Names: '|':UIView:0x174382cb0 )>", "<NSLayoutConstraint:0x17469c390 H:|-(10)-[UIImageView:0x1743e5e00] (Names: '|':UIView:0x174382cb0 )>", "<NSLayoutConstraint:0x17469c3e0 V:|-(10)-[UIImageView:0x1743e5e00] (Names: '|':UIView:0x174382cb0 )>", "<NSLayoutConstraint:0x17469c430 V:[UIImageView:0x1743e5e00]-(10)-[UILabel:0x13f64f2d0'\U51fa\U5ddd\U300c\U5168\U8eab\U306e\U9aa8\U3092\U6298\U3063\U305f\U4ffa\U306b\U3059\U308c\U3070\U3001\U8db3\U306e\U6307\U306a\U3069\U3069\U3046\U3067...']>", "<NSLayoutConstraint:0x17469c520 V:[UILabel:0x13f64ec00]-(10)-| (Names: '|':UIView:0x174382cb0 )>", "<NSLayoutConstraint:0x17469c5c0 V:[UILabel:0x13f64f2d0'\U51fa\U5ddd\U300c\U5168\U8eab\U306e\U9aa8\U3092\U6298\U3063\U305f\U4ffa\U306b\U3059\U308c\U3070\U3001\U8db3\U306e\U6307\U306a\U3069\U3069\U3046\U3067...']-(>=10)-[UILabel:0x13f64ec00]>", "<NSLayoutConstraint:0x17469c1b0 H:|-(0)-[UIView:0x174382cb0] (Names: '|':XXX.ArticleCollectionViewCell:0x13f64e910 )>", "<NSLayoutConstraint:0x17469c660 H:[UIView:0x174382cb0]-(0)-| (Names: '|':XXX.ArticleCollectionViewCell:0x13f64e910 )>", "<NSLayoutConstraint:0x17469c7f0 V:|-(0)-[UIView:0x174382cb0] (Names: '|':XXX.ArticleCollectionViewCell:0x13f64e910 )>", "<NSLayoutConstraint:0x17469c250 V:[UIView:0x174382cb0]-(0)-| (Names: '|':XXX.ArticleCollectionViewCell:0x13f64e910 )>", "<NSLayoutConstraint:0x1708901d0 'UIView-Encapsulated-Layout-Width' H:[XXX.ArticleCollectionViewCell:0x13f64e910(207)]>", "<NSLayoutConstraint:0x170890040 'UIView-Encapsulated-Layout-Height' V:[XXX.ArticleCollectionViewCell:0x13f64e910(102)]>" ) Will attempt to recover by breaking constraint <NSLayoutConstraint:0x17469c750 UIImageView:0x1743e5e00.width == 1.33333*UIImageView:0x1743e5e00.height> Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
<NSLayoutConstraint:0x170890040 'UIView-Encapsulated-Layout-Height' V:[XXX.ArticleCollectionViewCell:0x13f64e910(102)]>
が私が想定していない制約です。
102の高さは、他のセルが前に使った?高さで、実際のセルの高さは300程度あります。102になることで<NSLayoutConstraint:0x17469c750 UIImageView:0x1743e5e00.width == 1.33333*UIImageView:0x1743e5e00.height>
の制約が破綻してしまいます。
UIView-Encapsulated-Layout-Height
がUICollectionViewLayoutのlayoutAttributesForItemAtIndexPath
と違うのが原因だと思うのですがUIView-Encapsulated-Layout-Height
はいつ更新されるのでしょうか。
現在は、以下のように代入のタイミングで制約を書き換えるコードを実行しています。この更新タイミングが悪いでしょうか。
警告が出ないようにするためのアドバイスをお願い致します。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as ArticleCollectionViewCell let articleColumn = articleColumns[indexPath.section] cell.style = articleColumn.cellStyles()[indexPath.row] cell.article = articleColumn.articles[indexPath.row] return cell }
var style: ArticleCollectionViewCellStyle = .Text { didSet { switch style { case .Text: self.imageView.addConstraint(self.imageHeightLayoutConstraint) self.imageView.removeConstraint(self.imageAspectRatio43LayoutConstraint) self.imageView.removeConstraint(self.imageAspectRatio169LayoutConstraint) self.imageVerticalLayoutConstraint.constant = 0.0 self.titleLabel.numberOfLines = 3 self.imageView.image = nil case .TopImageFlexible: self.imageView.removeConstraint(self.imageHeightLayoutConstraint) self.imageView.removeConstraint(self.imageAspectRatio43LayoutConstraint) self.imageView.removeConstraint(self.imageAspectRatio169LayoutConstraint) self.imageVerticalLayoutConstraint.constant = 10.0 self.titleLabel.numberOfLines = 4 case .TopImageAspectRatio43: self.imageView.removeConstraint(self.imageHeightLayoutConstraint) self.imageView.addConstraint(self.imageAspectRatio43LayoutConstraint) self.imageView.removeConstraint(self.imageAspectRatio169LayoutConstraint) self.imageVerticalLayoutConstraint.constant = 10.0 self.titleLabel.numberOfLines = 3 case .TopImageAspectRatio169: self.imageView.removeConstraint(self.imageHeightLayoutConstraint) self.imageView.removeConstraint(self.imageAspectRatio43LayoutConstraint) self.imageView.addConstraint(self.imageAspectRatio169LayoutConstraint) self.imageVerticalLayoutConstraint.constant = 10.0 self.titleLabel.numberOfLines = 3 } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/03/21 13:38