Swift国内社区: SwiftMic
本篇文章介绍如何实现 iOS 切换 app 预览模糊的效果。
最终效果:
只需修改 AppDelegate.swift
即可。
首先声明一个变量 mBlurView
private var mBlurView: UIView!
增加 getBlurView()
方法
private func getBlurView() -> UIView {
if nil == mBlurView {
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = UIScreen.mainScreen().bounds
mBlurView = blurEffectView
}
return mBlurView
}
当 app 处于 inactive 状态时, 添加 blur view 。
func applicationWillResignActive(application: UIApplication) {
// Add blur view
UIApplication.sharedApplication().keyWindow?.addSubview(getBlurView())
}
当 app 处于 active 状态时, 移除 blur view 。
func applicationDidBecomeActive(application: UIApplication) {
// Remove blur view
if nil != mBlurView {
mBlurView.removeFromSuperview()
}
}
完整代码示例: iOSDemoCollection -> BlurDemo