【问题标题】:Blur Effect showing in simulator but not on the iPhone模糊效果在模拟器中显示,但在 iPhone 上没有
【发布时间】:2014-12-18 22:51:41
【问题描述】:

我想使用下面的代码在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 操作系统是 8.1.2

【问题讨论】:

  • 什么样的 iPhone?出于性能考虑,iPhone 4S 不支持模糊效果,而是显示纯色背景。以及我相信的第 2 代到第 4 代 iPad。
  • 这是一部新 iPhone 6

标签: ios iphone xcode swift


【解决方案1】:

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

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

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

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-21
    • 1970-01-01
    • 2012-03-08
    • 2010-12-19
    • 1970-01-01
    • 1970-01-01
    • 2013-05-13
    相关资源
    最近更新 更多