IBAction에 연결된 기본 UIButton이 있습니다 (내부 손질). 이것은 잘 작동하므로 내 연결이 정상이라는 것을 알고 있습니다. UIButton 클래스를 내 사용자 지정 버튼으로 변경하면 IBAction이 더 이상 트리거되지 않습니다. 아래는 내 사용자 지정 UIButton의 코드입니다. 왜 이런 일이 발생하는지 아이디어가 있습니까?
import UIKit
@IBDesignable
class PrimaryButton: UIButton {
override init(frame: CGRect) {
super.init(frame: frame)
initView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
initView()
}
private func initView() {
let view = viewFromNibForClass()
view.frame = bounds
view.autoresizingMask = [
UIViewAutoresizing.flexibleWidth,
UIViewAutoresizing.flexibleHeight
]
addSubview(view)
}
private func viewFromNibForClass() -> UIView {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: String(describing: type(of: self)), bundle: bundle)
let view = nib.instantiate(withOwner: self, options: nil).first as! UIView
return view
}
}
버튼이 더 이상 터치를받지 않기 때문에 코드가 작동하지 않습니다. 모든 터치는 추가 한 최상위 사용자 정의보기로 전송됩니다.
view.userInteractionEnabled = false
터치시 투명하게 설정 합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다