我试图像2014年的WWDC会议214那样制作一个popover.
所以我开始使用具有两个视图的IB构建我的应用程序,这两个视图通过“Present As Popover”segue连接,如下:
弹出视图包含一个填充其超级视图的文本视图,具有以下约束:
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.起初我只是在显示的控制器视图中添加一个子视图,在检查了视图层次结构后,我意识到我的效果视图实际上是在我的文本视图之上,但是我的文本视图被正确放置了.所以我尝试了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,animated: true) controller.presentedViewController.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[effectView]|",options: nil,metrics: nil,views: viewList)) controller.presentedViewController.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-[effectView]|",views: viewList)) return navigationController }
但我仍然无法呈现IB中定义的文本视图:
通过视图层次结构,我可以看到,当我在索引0处插入UIVisualEffectView时,我的文本视图以某种方式移动到导航栏下方.
有关如何以编程方式将模糊效果设置在文本下方而不使其消失/移动到导航栏下方的任何想法?
干杯
这个功能对你有帮助吗?
原文链接:/swift/319073.htmlview.insertSubview(view: effectView,belowSubview: label)