我正在尝试制作一个类似于 2014 年 WWDC 第 214 次 session 中的弹出窗口。
因此,我开始使用 IB 构建我的应用程序,该 IB 具有通过“Present As Popover”segue 连接的两个 View ,如下所示:
弹出 View 包含一个填充其父 View 的 TextView ,具有以下约束:
为了支持模态弹出框,代码如下:
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return .OverFullScreen
}
func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
let navigationController = UINavigationController(rootViewController: controller.presentedViewController)
controller.presentedViewController.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "done"), animated: true)
return navigationController
}
这给了我以下结果:
然后我尝试添加具有模糊效果的 UIVisualEffectView。起初我只是简单地向呈现的 Controller View 添加一个 subview ,在检查 View 层次结构后我意识到我的效果 View 实际上在我的 TextView 之上,但我的 TextView 放置正确。所以我尝试了 insertSubview: atIndex: 这样的方法:
func presentationController(controller: UIPresentationController, viewControllerForAdaptivePresentationStyle style: UIModalPresentationStyle) -> UIViewController? {
let effectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light)) as UIVisualEffectView
effectView.setTranslatesAutoresizingMaskIntoConstraints(false)
controller.presentedViewController.view.insertSubview(effectView, atIndex: 0)
let viewList : [String : UIView] = ["effectView" : effectView]
let navigationController = UINavigationController(rootViewController: controller.presentedViewController)
controller.presentedViewController.navigationItem.setRightBarButtonItem(UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "done"), animated: true)
controller.presentedViewController.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[effectView]|", options: nil, metrics: nil, views: viewList))
controller.presentedViewController.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[effectView]|", options: nil, metrics: nil, views: viewList))
return navigationController
}
但我仍然无法呈现 IB 中定义的 TextView :
通过 View 层次结构,我可以看到当我在索引 0 处插入 UIVisualEffectView 时,我的 TextView 以某种方式移动到导航栏下方。
关于如何以编程方式在文本下方设置模糊效果而不使其消失/移动到导航栏下方,有什么想法吗?
干杯
最佳答案
这个功能对你有帮助吗?
view.insertSubview(view: effectView, belowSubview: label)
关于swift - iOS 8 : Applying a UIVisualEffectView with Blur Effect to a Modal PopOver in Compact Mode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27097179/