From 4d2464ede2aefc32c1b60e5bb67940d1e1671c0d Mon Sep 17 00:00:00 2001 From: baegteun Date: Wed, 14 Aug 2024 22:26:21 +0900 Subject: [PATCH] =?UTF-8?q?:dizzy:=20::=20[#1114]=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=95=84=20=EB=B2=84=ED=8A=BC=20bouncy=20=ED=9A=A8=EA=B3=BC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Views/ProfileView.swift | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/Projects/Features/MyInfoFeature/Sources/Views/ProfileView.swift b/Projects/Features/MyInfoFeature/Sources/Views/ProfileView.swift index a72b675cd..8a27a11af 100644 --- a/Projects/Features/MyInfoFeature/Sources/Views/ProfileView.swift +++ b/Projects/Features/MyInfoFeature/Sources/Views/ProfileView.swift @@ -1,6 +1,7 @@ import DesignSystem import Kingfisher import RxCocoa +import RxGesture import RxSwift import SnapKit import Then @@ -22,6 +23,7 @@ final class ProfileView: UIView { $0.contentMode = .scaleAspectFill $0.layer.cornerRadius = 92 / 2.0 $0.clipsToBounds = true + $0.isUserInteractionEnabled = true } private let nameLabel = WMLabel( @@ -48,10 +50,15 @@ final class ProfileView: UIView { $0.numberOfLines = .zero } + fileprivate let didTapProfileImageSubject = PublishSubject() + private let scaleDownTransform = CGAffineTransform(scaleX: 0.9, y: 0.9) + private let disposeBag = DisposeBag() + init() { super.init(frame: .zero) addView() setLayout() + registerGesture() } @available(*, unavailable) @@ -77,7 +84,7 @@ final class ProfileView: UIView { } } -extension ProfileView { +private extension ProfileView { func addView() { self.addSubview(imageView) self.addSubview(nameLabel) @@ -103,6 +110,31 @@ extension ProfileView { $0.centerX.equalToSuperview() } } + + func registerGesture() { + imageView.rx.longPressGesture(configuration: { gestureRecognizer, delegate in + gestureRecognizer.minimumPressDuration = 0.0 + delegate.selfFailureRequirementPolicy = .always + }) + .bind(with: self) { owner, gesture in + switch gesture.state { + case .began: + UIViewPropertyAnimator(duration: 0.1, curve: .easeInOut) { + owner.imageView.transform = owner.scaleDownTransform + } + .startAnimation() + case .ended, .cancelled: + let animator = UIViewPropertyAnimator(duration: 0.3, dampingRatio: 0.5, animations: { + owner.imageView.transform = .identity + }) + animator.startAnimation() + owner.didTapProfileImageSubject.onNext(()) + default: + break + } + } + .disposed(by: disposeBag) + } } extension ProfileView: ProfileStateProtocol { @@ -140,9 +172,7 @@ extension ProfileView: ProfileStateProtocol { extension Reactive: ProfileActionProtocol where Base: ProfileView { var profileImageDidTap: Observable { - let tapGestureRecognizer = UITapGestureRecognizer() - base.imageView.addGestureRecognizer(tapGestureRecognizer) - base.imageView.isUserInteractionEnabled = true - return tapGestureRecognizer.rx.event.map { _ in }.asObservable() + return base.didTapProfileImageSubject.asObserver() + .throttle(.milliseconds(500), latest: false, scheduler: MainScheduler.asyncInstance) } }