尝试运行以下代码时出现此错误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)
}
}