在模拟器中显示模糊效果,但在iPhone上却没有显示。

3

我想在UIImageView上创建一个模糊效果,使用以下代码。问题是,当我在模拟器中运行时,可以看到模糊效果,但连接我的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操作系统版本是8.1.2。


1
什麼樣的iPhone?iPhone 4S出於性能考慮不支持模糊效果,而是顯示單色背景。同樣的,iPad第二代到第四代也是如此。 - Jordan H
这是一款全新的 iPhone 6。 - Armin Scheithauer
1个回答

5

检查用户是否未禁用透明效果:

if !UIAccessibilityIsReduceTransparencyEnabled() {
   //your code for blur

} else {
    //do something else, add a solid color, etc

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接