0

UICollectionViewCell自動レイアウトの制約があります。それはアスペクトとして機能しますが、私のアプリケーションは満たされていない制約に関する多くの警告を出力します:

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:0x7f9e650c50f0 UILabel:0x7f9e650c10c0'Toz     Kat Elek >30'.top == UIView:0x7f9e650c0fd0.topMargin - 8>",
    "<NSLayoutConstraint:0x7f9e650c51e0 UIView:0x7f9e650c17f0.top == UILabel:0x7f9e650c10c0'Toz     Kat Elek >30'.top + 20>",
    "<NSLayoutConstraint:0x7f9e650c5280 UIView:0x7f9e650c0fd0.bottomMargin == UIView:0x7f9e650c17f0.bottom - 8>",
    "<NSAutoresizingMaskLayoutConstraint:0x7f9e650d8550 h=--& v=--& V:[UIView:0x7f9e650c0fd0(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f9e650c5280 UIView:0x7f9e650c0fd0.bottomMargin == UIView:0x7f9e650c17f0.bottom - 8>

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.

問題の原因を突き止めるために、さまざまな組み合わせを試しました。Debug View Hierarchy を使用してビュー階層を調べているときに、追加していない UIView があり、この UIView が原因で警告メッセージが表示されることがわかりました。 非表示の UIView

では、これらの警告メッセージを取り除くにはどうすればよいでしょうか?

アップデート

ここに私のビュー階層があります:

階層

見る

4

4 に答える 4

1

OK, I have found my answer here: Auto layout constraints issue on iOS7 in UITableViewCell

The problem was about hidden content view of the cell. To get rid of the errors do following before returning the cell in cellForItemAtIndexPath:

cell.contentView.frame = cell.bounds;
cell.contentView.autoresizingMask =
UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleHeight |
UIViewAutoresizingFlexibleBottomMargin;
于 2015-02-12T08:18:28.007 に答える
0

エラーから何が起こっているかを読み取ることができます: あなたのラベルとその下の otherView は、mysteryView に添付され、ラベルは上部から 8 つ、次に otherView を 20 分離し、otherView の下部から 8 つが mysteryView に接続されます。非常に標準的です。ただし、autoresizingMask は、mysteryView を高さゼロに設定しています。両方を満たすことはできないため、otherView を下に保持する制約を破ります。MysteryView は高さがゼロになり (ただし、明らかに一番上の位置にとどまります)、Label はそれから 8 つ離れていき、otherView が一番下の何も接続されなくなるまで続きます。

ミステリービューは UILabel と otherView にアタッチされているため、それを見つけたり、制約を破ったりすることができるはずです。「Toz Kat Elek >30」というテキストを取得するラベルを見つけ、そのサイズ インスペクター (右側のパネルの定規アイコン) を確認します。-8 で上部スペースに接続する制約を見つけます。複数ある可能性があり、これが問題の一部になります。それをダブルクリックすると、IB ウィンドウの左側にあるドキュメント アウトラインで強調表示され、制約の詳細がインスペクターに表示されます。

UILabel やその他の要素に関連付けられていると思われるビューしか見つからない場合は、それらのビューを調べてください。下部のボタンを使用してすべての制約をクリアし、最初からやり直すことができます。

ただし、mysteryView を見つけて、それが実際に密航者 (明らかに高さがゼロ) である場合は、それを削除してください。ラベルとビューに添付された制約は機能していたので、新しいものを追加して、上部と下部を実際の上部と下部のスーパービューに接続する必要があるかもしれません。

于 2015-02-03T23:44:29.753 に答える
0

問題はその隠れた見方ではないと思います。UICollectionViewCellのような contentview がありUITableViewCellます。制約の競合は約 のようですUILabel

ストーリーボードのスクリーンショットを撮っていただけると助かります。

于 2015-01-23T19:28:43.920 に答える