仕事と私はviewDidAppear
にこのコードを呼び出すこのXIB、中央に高さを修正 - プログラム的制約は、私は自由形式で.xibを作成
if let alertView = Bundle.main.loadNibNamed(Constants.XIB.titleImageLabelThreeButtonsAlertView, owner: self, options: nil)?.first as? TitleImageLabelThreeButtonsAlertView {
view.addSubview(alertView)
alertView.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
view.addConstraint(NSLayoutConstraint(item: alertView, attribute: .trailing, relatedBy: .equal, toItem: view, attribute: .trailing, multiplier: 1, constant: 20))
view.addConstraint(NSLayoutConstraint(item: alertView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1, constant: 20))
alertView.autoresizingMask = [UIViewAutoresizing.flexibleLeftMargin, UIViewAutoresizing.flexibleRightMargin, UIViewAutoresizing.flexibleTopMargin, UIViewAutoresizing.flexibleBottomMargin]
self.view.layoutIfNeeded()
}
のようにそれを実装していないようです。中心的なことはうまくいくようですが、trailing
とleading
は効果がないようです。私は彼らの距離を20にしたい、私のalertView
は、固定された高さとセンターに表示する必要があります。
XIBが常に同じ大きさ(スクリーンショットを参照)
私が最初に目標としているが、私はすべてのデバイスのためのすべてのビューに実装することができますXIBを取得することでした。だからこれを得るための最善の方法は何ですか?
私XIBファイル シミュレータiphone 7 シミュレータiphone 4
私はオートレイアウトと自動サイズ変更のマスクを混ぜるのは良いアプローチではないと思います。これらは、衝突して未定義の結果を生む2つの異なるメカニズムです。 –
お返事ありがとうございます。私は何をしたいのかを知る方法を知っていますか? – kuzdu
自動サイズ変更マスクを設定するのではなく、 'subview.translatesAutoresizingMaskIntoConstraints = false'をキャンセルしてください。さらに、垂直方向の拘束(高さまたはyオフセット)を設定しないと、不適切な結果が生じる可能性があります。 –