ios - 快速模糊背景和清晰的 subview

标签 ios swift uiblureffect

我想要一个模糊的背景。我有一个主视图的 subview 。我希望 subview 不受模糊的影响。我该怎么办?

代码:

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
        let blurEffectView = UIVisualEffectView(effect: blurEffect)

        blurEffectView.frame = view.bounds


 let vibrancyEffect = UIVibrancyEffect(blurEffect: blurEffect)
   let vibrancyEffectView = UIVisualEffectView(effect: vibrancyEffect)
        vibrancyEffectView.frame = view.bounds

       view.addSubview(blurEffectView)

        view.addSubview(vibrancyEffectView)


        FrameView = UIView()


        if let FrameView = FrameView {

            FrameView.layer.borderColor = UIColor.white.cgColor
            FrameView.layer.borderWidth = 2
 FrameView.frame=CGRect(x:30,y:(view.frame.height/2-50),width:view.frame.width-60,height:100)
            blurEffectView.contentView.addSubview(FrameView)


   }

所以我希望 View 模糊,而 FrameView 清晰。

这就是我的应用程序目前的样子。

最佳答案

我尝试了一个测试项目,我首先将模糊添加到 mainView ,然后将 frameView 添加到 mainView ,我似乎很好,frameView 不模糊。

    let mainView = UIImageView.init(frame: self.view.bounds);
    mainView.image = UIImage.init(named: "a.png");
    let blurEffect = UIBlurEffect.init(style: .dark);
    let effectView = UIVisualEffectView.init(effect: blurEffect);
    effectView.frame = mainView.bounds;
    effectView.alpha = 1;

    let frameView = UIImageView.init(frame: CGRect.init(x: 0, y: 0, width: 200, height: 50));
    frameView.image = UIImage.init(named: "b.png");
    frameView.center = self.view.center;
    //add the blur view first
    mainView.addSubview(effectView);
    self.view.addSubview(mainView);
    self.view.addSubview(frameView);

enter image description here

关于ios - 快速模糊背景和清晰的 subview ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44276939/

相关文章:

ios - 选择 List<T> 关系的所有记录到 Results<T>?

iOS图像模糊效果与类别

ios - 在 UISplitView 的主视图中实现统一的 UIBlurEffect

swift - 为什么在 Realm 迁移期间会出现此错误? : 'RLMException' , 原因: 'Invalid value for property'

ios - 在 iOS 的组合框架中添加发布者发出的值之间的延迟

Swift - 检测项目是否被插入到 NSMutableSet

ios - 检测设备是否正确显示 UIVisualEffectView?

ios - Swift 中的持久数据

ios - Swift 3 Firebase : current user login success, 事件已在 Firebase 控制台中删除此用户

ios - 带有 TextKit 的 UITextView 中的动画 UIImage