ios - 使用弹出库时的不同 View 层次结构

标签 ios swift popup

我试图在单击 TableView 上的按钮时显示弹出窗口,使用 SCLAlertView-Swift图书馆。

我还尝试定义约束,以便旋转设备时尺寸正确。但是,它给了我以下错误:

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

我想我正在尝试从 TableViewController 获取 View ,因为我从该类调用此代码。

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: "")

为什么它说我引用了不同 View 层次结构中的项目?我该怎么做才能解决这个问题?

提前谢谢您。

最佳答案

查看 SCLAlertView 的实现 here ,它似乎是作为 UIApplication.shared.keyWindow 的 subview 添加的。

我建议将约束挂接到应用程序的 UIWindow 上,而不是 TableViewController 的 View 上。

let rv = UIApplication.shared.keyWindow! as UIWindow
let margins = rv.layoutMarginsGuide

关于ios - 使用弹出库时的不同 View 层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40961010/

相关文章:

javascript - 用于模态弹出窗口的 SlideUp Jquery

jquery - 如何将弹出窗口附加到 div

ios - kontakt.io sdk 在终止状态下不工作

ios - 在 SplitViewController 中从 DetailViewController 隐藏 MasterViewController

html - 如何允许用户使用 <input> 在 iOS 数字键盘中输入 "."?

swift - WKWebView 的 didFinishLoadForFrame

ios - 使用 NSFetchedResultsController 排序时在多个部分中的一个对象

swift - 如何使用 UISwipeGestureRecognizer 而不是与 Swift 和 SpriteKit 一起使用 TouchMoved?

ios - 当变量满足条件时显示 UIView

jquery - 如何启用弹出父页面滚动?