2017-12-02 9 views
1

私は自分が望むことをすることができない非常に簡単な設定をしています。UIViewの高さの制約が子ビューの高さの制約を破る

inputAccessoryViewを追加しようとしています。

inputAccessoryViewのために私はサブビュー(ViewB)でUIViewViewA)を持っています。 ViewBは、ViewAのすべてのエッジに固定されています。 ViewBは固定高さであり、両方の高さである必要があります。ViewAおよびViewB

ViewAさんは、私が設定したが、ViewB(42に設定)の高さを壊す0ですされていません。

ViewAは、底部と前縁及び後縁の両方(ViewAViewBのように幅にUIViewControllerのビューにサブビューとして追加されて固定されているのUIViewControllerのビュー、のものであるべきそれです)。

ここで私が持っているコードです:

override init(frame: CGRect) { 
    super.init(frame: frame) 

    let viewB = UIView() 
    addSubview(viewB) 

    viewB.translatesAutoresizingMaskIntoConstraints = false 
    viewB.topAnchor.constraint(equalTo: topAnchor).isActive = true 
    viewB.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true 
    viewB.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true 
    viewB.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true 
    viewB.heightAnchor.constraint(equalToConstant: 42).isActive = true 
} 

次のエラーになり:

2017-12-02 15:44:59.150228-0800 Ping[37511:5808904] [LayoutConstraints] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x608000283b60 h=--& v=--& MyApp.ViewA:0x7fe606511360.height == 0 (active)>", 
    "<NSLayoutConstraint:0x608000282030 UIView:0x7fe606511550.height == 42 (active)>", 
    "<NSLayoutConstraint:0x608000281d60 V:|-(0)-[UIView:0x7fe606511550] (active, names: '|':MyApp.ViewA:0x7fe606511360)>", 
    "<NSLayoutConstraint:0x608000281ef0 UIView:0x7fe606511550.bottom == MyApp.ViewA:0x7fe606511360.bottom (active)>" 
) 

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x608000282030 UIView:0x7fe606511550.height == 42 (active)> 

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. 

ViewAはかなり簡単セットアップを持っています

extension MessageViewController { 

    open override var canBecomeFirstResponder: Bool { 
     return true 
    } 

    open override var inputAccessoryView: UIView? { 
     return messageInputView 
    } 

} 

なぜはありませんが、 ViewA彼私が設定した制約を破ることは決してないのですか?

+0

@RuslanSerebriakov私は上記のコードを更新しました – runmad

答えて

1

私は解決策は、自動サイズ変更がViewAためのマスク無効にすることだと思う:

viewA.translatesAutoresizingMaskIntoConstraints = false 

あなたは制約でそれをレイアウトしているので。今度は問題を引き起こすViewAの高さを0に設定しようとします。

+0

私はいくつかの詳細を追加しました。これは 'inputAccessoryView'ですが、それを通常のサブビューとして追加すると、高さのために幅と垂直位置があいまいになります。 – runmad

+0

viewAの高さは0です(現在のケースは隠れているようです)。 –

+0

ViewAは、そのサブビューが設定されているサイズである必要があります。 – runmad

関連する問題