本文介绍了iOS,可以从iOS9 +获得本机模糊视图效果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示视图/弹出窗口(对话框),但是我需要在背景中使用模糊效果并支持iOS 9 +.

I'm trying to show a view / popup (a dialog), however I need a blur effect in the background and support iOS 9+.

它们是否模糊了UIKit本身提供的支持旋转的操作?

Are they blur operations provided natively in UIKit which will support rotation?

我担心模糊效果会在屏幕截图上起作用,一旦我显示了对话框并且屏幕旋转,就无法在屏幕截图图像上添加模糊效果.

I'm concerned that the blur effect will work off a screenshot and once I've shown my dialog and the screen rotates it won't be possible to add a blur effect to the screenshot image.

也许还有其他选择.

推荐答案

UIKIt具有UIVisualEffectView来添加漂亮的模糊效果

UIKIt has a UIVisualEffectView to add the beautiful blur effects

  • 从对象库中拖动一个UIVisualEffectView并将其放在需要针对您的情况(背景)使其模糊的视图上

声明这些属性

@IBOutlet var popupView: UIView!
@IBOutlet weak var visualEffectView: UIVisualEffectView!
var blurEffect:UIVisualEffect!

在viewDidLoad中输入此代码

in viewDidLoad put this code

    blurEffect = visualEffectView.effect
    visualEffectView.effect = nil

显示带有模糊的视图/弹出窗口(对话框)

show a view/popup (a dialog) with blur

func presentPopUp() {
    self.view.addSubview(popupView)
    UIView.animate(withDuration: 0.4) {
        self.visualEffectView.effect = self.blurEffect
       //make tarnsform from  popupView make it show more beauty
    }
}

隐藏视图/弹出窗口(对话框)并模糊

hide a view/popup (a dialog) and blur

func dismissPopUp () {
    UIView.animate(withDuration: 0.3, animations: {
        self.visualEffectView.effect = nil
        //make tarnsform from  popupView make it hide more beauty
    }) { (success:Bool) in
        //  dismissPopUp remove it from super View
    }
}

这篇关于iOS,可以从iOS9 +获得本机模糊视图效果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 08:23