swift – iOS 8:将具有模糊效果的UIVisualEffectView应用于紧凑模式下的模态PopOver

我试图像2014年的WWDC会议214那样制作一个popover.

所以我开始使用具有两个视图的IB构建我的应用程序,这两个视图通过“Present As Popover”segue连接,如下:

弹出视图包含一个填充其超级视图的文本视图,具有以下约束:

为了支持模态popover,可以使用以下代码

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时,我的文本视图以某种方式移动到导航栏下方.

有关如何以编程方式将模糊效果设置在文本下方而不使其消失/移动到导航栏下方的任何想法?

干杯

这个功能对你有帮助吗?
view.insertSubview(view: effectView,belowSubview: label)

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...