Swift   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift – iOS 8:将具有模糊效果的UIVisualEffectView应用于紧凑模式下的模态PopOver大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

概述

我试图像2014年的WWDC会议214那样制作一个popover. 所以我开始使用具有两个视图的IB构建我的应用程序,这两个视图通过“Present As Popover”segue连接,如下: 弹出视图包含一个填充其超级视图的文本视图,具有以下约束: 为了支持模态popover,可以使用以下代码: func adaptivePresentationStyleForPresentationCont
@H_874_6@
@H_874_6@
我试图像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)

大佬总结

以上是大佬教程为你收集整理的swift – iOS 8:将具有模糊效果的UIVisualEffectView应用于紧凑模式下的模态PopOver全部内容,希望文章能够帮你解决swift – iOS 8:将具有模糊效果的UIVisualEffectView应用于紧凑模式下的模态PopOver所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
猜你在找的Swift相关文章