Search code examples
ioscocoa-touchuikit

iOS, native blur view effects available from iOS9+?


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.


Solution

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