UIVisualEffectView 对象提供了一种简单的方法实现一些复杂的视觉效果
使用注意:
如果想对其增加子视图时候,不应该直接添加子视图到 UIVisualEffectView视图中,而是添加到 UIVisualEffectView 对象的 contentView 中
import UIKit
class ViewController: UIViewController {
var imageView:UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
imageView = UIImageView(frame: self.view.bounds)
imageView.image = UIImage(named: "imageName")
imageView.contentMode = .ScaleAspectFill //图片适配样式
imageView.userInteractionEnabled = true //用户交互
let tapGestureRecognizer = UISwipeGestureRecognizer(target: self, action: "swipeEvent")
imageView.addGestureRecognizer(tapGestureRecognizer) //增加滑动手势
self.view.addSubview(imageView)
}
func swipeEvent() {
let blurEffect = UIBlurEffect(style: .Light) // 模糊样式
let effectView = UIVisualEffectView(effect: blurEffect)
effectView.frame = CGRect(x: 0, y: 0, width: imageView.frame.width/2, height: self.view.frame.height)
imageView.addSubview(effectView)
}
}