繁体   English   中英

对象与协议的冗余一致性

[英]Redundant conformance of Object to Protocol

尝试运行以下代码时,出现Redundant conformance of 'AnyView' to protocol 'Pressable'错误。 任何人都可以显示错误或使用协议执行相同登录的任何其他方式。

class AnyView: UIView, Pressable {

}

// MARK: - Pressable

protocol Pressable: UIView {

}

extension UIView: Pressable {
    // touchesBegan
    override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
        scaleAnimation(value: 0.8)
    }
}

你只需要摆脱对AnyView一致性,以Pressable ,因为它的超UIView已符合Pressable

class AnyView: UIView {

}

// MARK: - Pressable

protocol Pressable: UIView {

}

extension UIView: Pressable {
    // touchesBegan
    override open func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
        scaleAnimation(value: 0.8)
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM