美文网首页
毛玻璃轮子

毛玻璃轮子

作者: 卡卡罗忒 | 来源:发表于2019-10-12 15:20 被阅读0次

    毛玻璃效果自定义值
    class AlphaBlurView: UIVisualEffectView {

    private let blurEffect: UIBlurEffect
    public var blurRadius: CGFloat {
        return blurEffect.value(forKeyPath: "blurRadius") as! CGFloat
    }
    
    public convenience init() {
        self.init(withRadius: 0)
    }
    
    public init(withRadius radius: CGFloat,tintColor: UIColor = #colorLiteral(red: 0.07843137255, green: 0.07843137255, blue: 0.07843137255, alpha: 0.9)) {
        let customBlurClass: AnyObject.Type = NSClassFromString("_UICustomBlurEffect")!
        let customBlurObject: NSObject.Type = customBlurClass as! NSObject.Type
        self.blurEffect = customBlurObject.init() as! UIBlurEffect
        self.blurEffect.setValue(1, forKeyPath: "scale")
        self.blurEffect.setValue(radius, forKeyPath: "blurRadius")
        self.blurEffect.setValue(tintColor, forKeyPath: "colorTint")
        self.blurEffect.setValue(1, forKeyPath: "colorTintAlpha")
        super.init(effect: radius == 0 ? nil : self.blurEffect)
    }
    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    public func setBlurRadius(radius: CGFloat) {
        guard radius != blurRadius else {
            return
        }
        blurEffect.setValue(radius, forKeyPath: "blurRadius")
        self.effect = blurEffect
    }
    

    }

    相关文章

      网友评论

          本文标题:毛玻璃轮子

          本文链接:https://www.haomeiwen.com/subject/vliqmctx.html