Last active
April 13, 2017 08:01
-
-
Save rayfix/af00a33914287835923e to your computer and use it in GitHub Desktop.
Another take on popup blurring inspired by http://www.totem.training/swift-ios-tips-tricks-tutorials-blog/ux-chops-dim-the-lights
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Blurring.swift | |
// TransitionDemo | |
// | |
// Created by Ray Fix on 1/7/16. | |
// | |
import UIKit | |
protocol Blurring {} | |
extension Blurring where Self: UIViewController { | |
func blurWithDuration(duration: NSTimeInterval) { | |
let blurView = UIVisualEffectView(frame: view.bounds) | |
blurView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] | |
view.addSubview(blurView) | |
UIView.animateWithDuration(duration) { | |
blurView.effect = UIBlurEffect(style: .Dark) | |
} | |
} | |
func unblurWithDuration(duration: NSTimeInterval) { | |
guard let blurView = view.subviews.last as? UIVisualEffectView else { return } | |
UIView.animateWithDuration(duration, animations: { | |
blurView.effect = nil | |
}, completion: { success in | |
blurView.removeFromSuperview() | |
}) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment