我在RXSwift类中有一个自定义控件。
我遵循了它,并且有效
Custom UIControl subclass with RxSwift
但是,我的实现在UIControl中有一个手势。所以我们有这个
var buttResponse: ControlEvent<()>?
let butt = SYYesNoButton(frame: CGRect(x: 0, y: 150, width: 100, height: 100))
self.view.addSubview(butt)
buttResponse = butt.rx.controlEvent(.touchUpInside)
buttResponse?.subscribe({aa in
print (aa.element!, "DD")
})
.disposed(by: disposeBag)
和一个按钮类
class SYYesNoButton: UIControl {
@IBAction func setLoadingAction(_ sender: UIButton? = nil) {
print ("loading action")
}
override init(frame: CGRect) {
super.init(frame: frame)
isExclusiveTouch = false
// the cause of the issue
self.addTarget(self, action: #selector(setLoadingAction(_:)), for: [.touchUpInside])
let tap = UITapGestureRecognizer(target: self, action: #selector(setLoadingAction(_:)))
self.addGestureRecognizer(tap)
}
override func layoutSubviews() {
super.layoutSubviews()
backgroundColor = isSelected ? .green : .red
}
override var isSelected: Bool {
didSet {
backgroundColor = isSelected ? .green : .red
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
现在,如果我们不添加手势,它将起作用。
如果我们添加手势,则不会。
在我的上下文中,我需要在按钮中具有手势,我想要该手势并具有controlEvent。