버튼이나, view에게 클릭했을 때 이벤트를 발생하도록 하는 방법이 두 가지정도 되는것같다.
UIView를 생성해서 UITapGestureRecognizer를 이용하거나,
let iv = UIView() let tap = UITapGestureRecognizer(target: self, action: #selector(handleProfileImageView)) iv.isUserInteractionEnabled = true iv.addGestureRecognizer(tap)
addTarget 함수를 이용하는 방법이다.
let button = UIButton() button.addTarget(self, action: #selector(tapFollowButton), for: .touchUpInside)
첫번째 방법은 UIView의 서브클래스 객체에게 사용할 수 있다고하고,
두번째 방법은 UIControl의 서브클래스 객체에게 쓸 수 있다고한다.
즉 UIContol의 서브클래스 객체는 두 방법 모두 이용할 수 있다.