2014-12-18 156 views
3

我想用下面的代码在UIImageView上创建模糊效果。问题是,当我在模拟器中运行它时,我可以看到BlurEffect,但当我连接我的iPhone时,却看不到它,这里我只能看到灰色的背景......任何想法? 这里是我使用的代码:我上的Xcode 6.1.1运行在模拟器中显示模糊效果,但不在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.2!),我的iPhone OS 8.1.2是

+1

什么样的iPhone? iPhone 4S不支持对性能问题的模糊效果,而是显示出纯色的背景色。除了iPad第二到第四代,我相信。 – Joey 2014-12-19 05:53:36

+0

它是一个新的iPhone 6 – 2014-12-19 13:49:51

回答

4

检查,如果用户没有禁用透明效果:

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

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

} 
+0

谢谢!这是问题,现在它工作正常......有时候简单的事情会导致严重的头痛......干杯! – 2014-12-19 13:56:44

+0

很高兴帮助你,快乐的编码! – TonyMkenu 2014-12-19 23:20:02

相关问题