2016-12-04 15 views
0

SCLAlertView-Swiftライブラリを使用して、TableViewのボタンをクリックするとポップアップが表示されるようにしようとしています。ポップアップライブラリを使用したときのビュー階層の相違

また、デバイスを回転させたときに寸法が正しいように制約を定義しようとしています。しかし、それは私に次のエラーを与える:

'UIViewLayoutMarginsGuide'.leading"> because they have no common ancestor. Does the constraint or its anchors reference items in different view hierarchies? That's illegal.'

私はそのクラスからこのコードを呼び出しているので、私は、私はTableViewControllerからビューを取得しようとしているものと想定です。

let alert = SCLAlertView() 

alert.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] 

let margins = view.layoutMarginsGuide 
alert.view.leadingAnchor.constraint(equalTo: margins.leadingAnchor).isActive = true 
alert.view.trailingAnchor.constraint(equalTo: margins.trailingAnchor).isActive = true 
alert.view.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 8).isActive=true 
alert.view.topAnchor.constraint(equalTo: view.topAnchor, constant: 8).isActive=true 

alert.showInfo("Login", subTitle: "") 

なぜ私は異なるビュー階層のアイテムを参照していますか?これを解決するために私は何ができますか?

ありがとうございます。

+0

'TableViewController'ビューではなく' UIApplication.shared.keyWindow'ビューにフックしてみましたか? – dirtydanee

答えて

0

SCLAlertViewhereの実装を見ると、UIApplication.shared.keyWindowのサブビューとして追加されたようです。

TableViewControllerのビューではなく、アプリケーションのUIWindowに制約をフックすることをお勧めします。

let rv = UIApplication.shared.keyWindow! as UIWindow 
let margins = rv.layoutMarginsGuide 
関連する問題