【问题标题】:Not able to get blur effect无法获得模糊效果
【发布时间】:2017-08-29 11:04:35
【问题描述】:

我在 storyBorad 中使用 UIVisual Effect 视图。我只是为该视图设置了四个约束(顶部、底部、左侧、右侧)。但它后面看起来有些黑色。

源代码:

import UIKit

class SignOutViewController: UIViewController {

    @IBOutlet weak var signouTitle: UILabel!
    @IBOutlet weak var desc1: UILabel!
    @IBOutlet weak var desc2: UILabel!
    @IBOutlet weak var cancelButton: UIButton!
    @IBOutlet weak var sureButton: UIButton!
    @IBOutlet weak var alertView: UIView!
    @IBOutlet weak var seperatorView: UIView!
    @IBOutlet weak var buttonsSuperView: UIView!

    override func viewDidLoad() {
        super.viewDidLoad()
        prepareAlertView()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        alertView.layer.cornerRadius = alertView.frame.height * 0.05

    }

    private func prepareAlertView() -> Void{
        signouTitle.text = "Sign Out"
        desc1.text = "Do you really want to sign out"
        desc2.text = "from this account"
        signouTitle.textColor = UIColor(red: 1 / 255, green: 170 / 255, blue: 112 / 255, alpha: 1)
        desc1.textColor = UIColor(red: 195 / 255, green: 195 / 255, blue: 195 / 255, alpha: 1)
        desc2.textColor = UIColor(red: 195 / 255, green: 195 / 255, blue: 195 / 255, alpha: 1)
        cancelButton.setAttributedTitle(NSAttributedString(string: "Cancel", attributes: [NSFontAttributeName: UIFont.getProximaNovaSemibold(size: 16), NSForegroundColorAttributeName: UIColor.white]), for: .normal)
        sureButton.setAttributedTitle(NSAttributedString(string: "Sure", attributes: [NSFontAttributeName: UIFont.getProximaNovaSemibold(size: 16), NSForegroundColorAttributeName: UIColor.white]), for: .normal)
        self.view.backgroundColor = UIColor.black.withAlphaComponent(0.65)
        buttonsSuperView.backgroundColor = UIColor(red: 1 / 255, green: 170 / 255, blue: 112 / 255, alpha: 1)
        alertView.backgroundColor = UIColor(red: 36 / 255, green: 36 / 255, blue: 40 / 255, alpha: 1)
    }

    @IBAction func cancelTapped(_ sender: Any) {
        self.dismiss(animated: true, completion: nil)
    }

    @IBAction func sureTapped(_ sender: Any) {
    }

}

我以编程方式添加了 UIVisual effectView。我需要visualEffect作为viewHierarchy中的第-1个位置。但它的响应相同..

【问题讨论】:

  • 提供你写的代码
  • @Praveen 源代码已添加到帖子中..

标签: objective-c swift swift3 uivisualeffectview uiblureffect


【解决方案1】:

试试这个

let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.dark)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = view.bounds
blurEffectView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.addSubview(blurEffectView)

【讨论】:

  • 感谢您的建议。但它也没有醒来。我更新了帖子,看看...
  • 我看到了你的截图你可以用 uiimage 来做到这一点,你必须制作一个左上角圆形切割和 Alpha ~0.8 的图像并采用 UIView 然后将 UIImageView 作为 UIView 的子类并将你的图像放入UIImageView 然后让你的弹出窗口确定或取消,最后你可以隐藏和显示你的 UIView。
【解决方案2】:

我遇到了完全相同的问题。我所做的只是使用了一个新的故事板,并使用屏幕截图中的设置以模态方式呈现它。然后模糊效果完美地工作而不是显示黑屏。如果您想以编程方式执行此操作,也可以将其转换为代码。

注意:这些设置用于转场。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    • 2023-01-01
    • 1970-01-01
    相关资源
    最近更新 更多