iOS, native blur view effects available from iOS9+?

一个人想着一个人 提交于 2020-01-24 20:19:08

问题


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

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.

Perhaps there are other options.


回答1:


UIKIt has a UIVisualEffectView to add the beautiful blur effects

  • from the object library drag a UIVisualEffectView and drop it on the view that needs make it blur for your case (background)

declare these properties

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

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
    }
}


来源:https://stackoverflow.com/questions/52374527/ios-native-blur-view-effects-available-from-ios9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!