SeSACButton 을 UIContorl을 서브클래싱 해서 만들었다.
touchupBegan에는 버튼의 배경색이 변하도록 내용이 작성 된 상태
다른 뷰에서 SeSACButton을 인스턴스화 하고 addAction(또는 타겟)을 했는데 핸들러가 동작을 안했다.
원인을 찾기 위해서 플레이그라운드를 만들어 동일한 SeSACButton을 클래스로 만들어서 테스트 했다.
플레이그라운드에서는 touchupBegan에 super를 호출 하니까 단번에 해결 되었다.
super 호출 문제로 생각하고 본 프로젝트에도 적용했으나 여전히 동작을 하지 않았다.
Stack Over Flow에 UIControl Subclassing으로 검색결과
UIControl에 입력이 들어오고, 바깥에서 addTarget, addAction으로 연결시키기 위해서는 클래스 안에서, sendAction의 발생 시점을 정의 해 주어야 한다.
public override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
sendActions(for: .touchUpInside)
guard style == .fill, animateOn, !isDisabled else { return }
UIView.animate(withDuration: 0.1) { [weak self] in
self?.containerView.backgroundColor = .seSACGreen.withAlphaComponent(0.5)
}
}