我想使用下面的代码在UIImageView
上创建模糊效果。问题是,当我在模拟器中运行它时,我可以看到BlurEffect,但是当我连接iPhone时,我看不到它,在这里我只能看到灰色的背景....任何想法?
这是我使用的代码:
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var myImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
self.myImageView.image = UIImage(named: "Desert.png")
let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.Light)
let blurView = UIVisualEffectView(effect: blurEffect)
blurView.frame.size = CGSize(width: 375, height: 667)
blurView.center = myImageView.center
self.myImageView.addSubview(blurView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我正在运行Xcode 6.1.1(也尝试过Xcode 6.2!),我的iPhone OS是8.1.2
答案 0 :(得分:4)
检查用户是否未禁用透明效果:
if !UIAccessibilityIsReduceTransparencyEnabled() {
//your code for blur
} else {
//do something else, add a solid color, etc
}