[iOS] RxGesture에 정리 기본
Gesture를 Rx형태로 사용할 수 있음.
오픈소스 없이 사용하는 방법
참고로 UIAction을 사용해서할 수도 있는데, 현재 대부분의 개발자가 해당 형태로 selector 활용하는 형태로 구현
private lazy var backView = UIView().then {
$0.backgroundColor = .lightGray
$0.alpha = 0.3
$0.isHidden = true
}
override func viewDidLoad() {
super.viewDidLoad()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTap(sender: )))
self.backView.addGestureRecognizer(tapGesture)
}
@objc
func didTap(sender: UITapGestureRecognizer) {
print("didTap")
}
RxGesture를 사용한 방식
보일러플레이트가 사라져서 코드가 더 깔끔해짐
var backView = UIView().then {
$0.backgroundColor = .lightGray
$0.alpha = 0.3
$0.isHidden = true
}
override func viewDidLoad() {
super.viewDidLoad()
backView.rx.tapGesture()
.when(.recognized) // bind시에도 이벤트가 발생하기 때문 .skip(1)으로도 처리 가능
.bind { _ in
print("didTap")
}
}
'project > Kuring(공지알림)' 카테고리의 다른 글
| [iOS] inAppReview(StoreKit) - 인앱 리뷰 (0) | 2022.03.06 |
|---|---|
| [iOS] Xcode Storyboard 제거 후 코드로 대체하는 방법 (0) | 2022.01.07 |
| iOS UIButton 90도 회전시키기 (0) | 2021.12.20 |
| iOS StackView Button 추가하기 (0) | 2021.12.19 |
| iOS SearchBar + RxSwift (0) | 2021.12.19 |