在模拟器中显示模糊效果,但在iPhone上不显示 [英] Blur Effect showing in simulator but not on the iPhone

查看:73
本文介绍了在模拟器中显示模糊效果,但在iPhone上不显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用以下代码在 UIImageView 上创建模糊效果.问题是,当我在Simulator中运行它时,我可以看到BlurEffect,但是当我连接iPhone时却看不到,在这里我只能看到灰色背景....任何想法?这是我使用的代码:

I wanted to create a blur effect on an UIImageView with the code below. The problem is that I can see the BlurEffect when I run it in the Simulator but not when I connect my iPhone, here I can only see a gray background....any ideas? Here is the code I used:

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

I am running on Xcode 6.1.1 (also tried Xcode 6.2!) and my iPhone OS is 8.1.2

推荐答案

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

Check if the user hasn't disabled transparency effects:

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

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

}

这篇关于在模拟器中显示模糊效果,但在iPhone上不显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆