iOS/코드조각

[iOS, Swift] 두개 이상의 뷰에 tapGesture 추가하기

검은참깨두유vm 2022. 6. 22. 09:09
반응형

iOS 15, Xcode 13.31, Swift 5, UIKit 환경에서 진행했습니다.

 

func setTapGesture() -> UITapGestureRecognizer { // TapGestureRecognizer 생성
    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap(sender:)))
    return tapGesture
}
@objc func handleTap(sender: UITapGestureRecognizer) { // tap 하였을 때 실행되는 함수
    print("handleTap")
}
topViewId.addGestureRecognizer(setTapGesture()) // 뷰에 tapGesture 등록

 

반응형