-
Notifications
You must be signed in to change notification settings - Fork 6
[Fix] #216 - 바텀 시트의 일부 기능을 수정 하였습니다. #217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The head ref may contain hidden characters: "#216---\uBC14\uD140-\uC2DC\uD2B8-\uC624\uB958-\uD574\uACB0"
Conversation
기존 일반 상수에서, 시스템을 활용한 코드로 대체 했습니다.
UIPanGestureRecognizer 를 추가하므로써, 유연하게 작동하는 바텀시트가 되었습니다.
513sojin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
화면 전환시 animated: false로 설정하고 바텀시트 내부에서 설정하는 방향이 좋아보입니다요
이렇게 애니메이션 넣던 코드 살리는거 어떠신지요,
UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseIn, animations: {
self.backgroundView.alpha = 0.0
self.view.layoutIfNeeded()
})
저번보다 훨씬 완성도 높은 바텀시트가 됐네요 수고하셨슴당 👍🏻👍🏻
라이브러리도 있는줄 몰랐는데 ㅎ... 배워갑니다 ^~^
- 오토레이아웃 관련 이슈인데
코멘트 남긴 부분이랑
bottomSheetTextField.snp.makeConstraints { make in
make.centerX.equalToSuperview() -> 이 부분 없어져도 될듯
make.top.equalTo(contentsLabel.snp.bottom).offset(19)
make.leading.trailing.equalToSuperview().inset(16)
make.height.equalTo(44)
}
여기 코드도 leading, trailing 값을 줬는데 centerX로 두번 레이아웃 잡아줄 필요 없을 것 같아요
확인 부탁드립니다 ~
| bottomSheetView.snp.remakeConstraints { make in | ||
| make.leading.bottom.trailing.equalToSuperview() | ||
| make.top.equalTo(view.snp.top).offset(topConst) | ||
| make.height.equalTo(bottomHeight) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
버튼 눌리는지 확인하다가 발견했는데 여기쪽에서 오토레이아웃 이슈가 나는 것 같아용

leading bottom trailing top 모두 오토레이아웃 잡힌 상태에서는
top / height 중 하나만 레이아웃을 잡아줘야 할 것 같고
make.top.equalTo(view.snp.top).offset(topConst) 이 부분이 빠져도 레이아웃 잘 잡힐 것 같아요 !! 확인 부탁드립니다 ~
*217번 코드도 동일해서 여기도 같이 확인 부탁드립니다
bottomSheetView.snp.makeConstraints { make in
make.leading.bottom.trailing.equalToSuperview()
make.top.equalTo(view.snp.top).offset(topConst)
make.height.equalTo(bottomHeight)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
본 이슈 는 레이아웃을 중복? 으로 사용되서 나오는 경고 같네요!
말씀해주신 부분 말고도 수정 완료 하였습니다!
코드리뷰 반영할때 중복되는 것도 한번더 꼼꼼하게 살펴보겠습니다.
| if let keyboardFrame: NSValue = sender.userInfo? [UIResponder.keyboardFrameEndUserInfoKey] as? NSValue { | ||
| let keybaordRectangle = keyboardFrame.cgRectValue | ||
| let keyboardHeight = keybaordRectangle.height | ||
|
|
||
| self.view.frame.origin.y -= (keyboardHeight - view.safeAreaInsets.bottom) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 291이라는 숫자로 하드코딩 하는것 대신 키보드 높이 값을 계산해서 뷰의 위치를 조정하도록 수정한건가요~?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
맞습니다!
이 부분은 구글링하여 참고했으며, 구글링한 코드를 약간 변형하였습니다.
다시 보니까 키보드 내리는 동작도 self.view.frame.origin.y = 0 가 아닌 올리는 동작과 비슷한 코드로 작성하는 게 더 좋을 것 같아서 수정하겠습니다~
@513sojin 최종 코멘트에서는 이렇게 밖에 리뷰를 달 수 없어가지고 다음부터는 해당 관련 코드에 남겨주시면 감사하겠습니다 👍👍 🔥
UIPanGestureRecognizer 중에는 다양한 케이스가 있는데 ( 여기서 사용한 건, 하지만 저 부분도 코드를 정리하면서 해결해 가겠습니다 😃 |
약간의 코드 수정이 있었습니다. 코드 선언위치, 키보드 위치 관련 코드, 뷰 배경 흐려짐 관련 코드를 수정 하였습니다.
513sojin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
짧은 시간 동안 많이 개선 됐네요 !!부라보
영상보니까 마지막에 언급한 부분 빼고는 다 완성된 것 같아요 넘 고생하셨습니다 🥹👍🏻👍🏻👍🏻
| case .ended: | ||
| // translation.y 값이 75보다 작으면(작게 이동 시) 뷰의 위치를 다시 원상복구하겠다. = 즉, 다시 y=0인 지점으로 리셋 | ||
| if translation.y < 75 { | ||
| backgroundView.alpha = 0.65 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
순서 바꿔주셨는데 이유가 있나여 ?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 어떤 순서를 말씀하시는 걸까요!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UIView.animate(withDuration: 0.25, animations: {
self.view.transform = .identity
})
backgroundView.alpha = 0.65
여기에서 backgroundView.alpha = 0.65 이 부분이 위로 올라왔길래 여쭤봤슴당~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아아 순서로 인한 뷰의 변화는 없고, 다 블록의 상단에 위치하여 보여주려고 가독성 위한!? 코드라고 보시면 됩니다!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋네용 답변 감사합니다 👍🏻
이제 백그라운드도 문제없이 작용합니다. 추가로 위로 스와이프 되는 코드도 추가하여 내리다가 다시 올릴 수 있습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
처음 보는 코드가 많아서 궁금한거 질문 달아뒀어요 !
어푸룹 해두었으니 머지하시고 편할 때 댓글 남겨주십쇼
수고하셨습니다 ~
| if velocity.y > 0 && translation.y > 0 { // 아래로만 Pan 가능한 로직 , 여기서 translation.y > 0 이거 추가 안해주면 재밌게 에니메이션이 움직인다.. | ||
| backgroundView.alpha = 0 | ||
| UIView.animate(withDuration: 0.25, animations: { | ||
| self.view.transform = CGAffineTransform(translationX: 0, y: translation.y) | ||
| }) | ||
| } else if velocity.y < 0 && translation.y > 0 { | ||
| // 위로도 움직이게는 하지만, 한계설정을 바텀시트의 높이로 설정, 즉 위쪽으로 하나도 못 움직이게 설정 ( translation.y > 0 ) 한계점 설정 | ||
| UIView.animate(withDuration: 0.25, animations: { | ||
| self.view.transform = CGAffineTransform(translationX: 0, y: translation.y) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
재밌게 애니메이션이 움직인다라 ㅋㅋㅋㅋㅋㅋㅋㅋ
velocity.y > 0 && translation.y > 0 이게 어떤 의미인지 여쭤봅니다 .. !@
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UIPanGestureRecognizer 를 아에 모른다고 하고 설명하겠습니다.
translation.y 이게 양수 라는 것은 아래로 내려 저희 벡터값이 양수가 된다는 의미 입니다.
velocity와 translation의 개념은 아래 블로그에서 참고하면 좋을 것 같아요!
https://zeddios.tistory.com/356
저 조건이 없다면 벡터값이 음수, 즉 위에서도 스와이프를 허락 한 것이니 UIPanGestureRecognizer가 작동이 되버려 원하지 않은 동작이 발생합니다.
&& translation.y > 0 이 코드를 추가 하지 않았으면 아래와 같이 노는? 느낌의 매우 이상한.. UI가 되어버립니다 ㅎㅎ
바텀시트 뿐만아니라 그 윗 부분까지도 인식이 되어 버리는거죠!!
RPReplay_Final1701164029.MP4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 !!! 남겨준 글(밑의 코멘트 포함)이랑 블로그 읽어보고 왔습니당
좋은 자료와 설명 감사합니다 쵝오
| // 애니메이션이 끝나면 실행될 코드 | ||
| self.backgroundView.alpha = 0.6 | ||
| }) | ||
| recognizer.setTranslation(CGPoint.zero, in: bottomSheetView) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이건 무슨 코드인가요 ? 궁금해여
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UIPanGestureRecognizer의 Action메소드가 호출되면, translation은 마지막으로 손가락을 이동한 위치에서부터 계산되지 않고, 손가락을 끌기 시작한 원래 장소!! (즉, 처음 PanGesture를 시작한 위치)에서 계산됩니다.
recognizer.setTranslation(CGPoint.zero, in: bottomSheetView)
그래서 우리는 위 메소드를 0.0으로 호출하여 UIPanGestureRecognizer에게 새로운 드래그 동작을 시작할 것임을 알리는 것이죠.
우리가 드래그를 이어서 한다고 해서 드래그가 한~~~번~~ 이런게 아닙니다. 늘 지속 됩니다 드래그는
UIPanGestureRecognizer의 Action메소드는 지속적이라고 그랬죠? 계속 Action메소드를 호출하게 됩니다.
한번 Action메소드가 호출될때마다 파라미터로 보내는 view의 translation을 0,0으로 setting 해줘야만하는것이죠.
안그러면 우리가 처음 드래그를 시작한 그 위치!!!에서 부터 계속 거리를 계산할것이니까요.
이해가 안된다면 해당 개념을 참고한 블로그에서 가져온 글이 있는데 참고하면 좋을 것 같습니다.!!
| if velocity.y > 0 && translation.y > 0 { // 아래로만 Pan 가능한 로직 , 여기서 translation.y > 0 이거 추가 안해주면 재밌게 에니메이션이 움직인다.. | ||
| backgroundView.alpha = 0 | ||
| UIView.animate(withDuration: 0.25, animations: { | ||
| self.view.transform = CGAffineTransform(translationX: 0, y: translation.y) | ||
| }) | ||
| } else if velocity.y < 0 && translation.y > 0 { | ||
| // 위로도 움직이게는 하지만, 한계설정을 바텀시트의 높이로 설정, 즉 위쪽으로 하나도 못 움직이게 설정 ( translation.y > 0 ) 한계점 설정 | ||
| UIView.animate(withDuration: 0.25, animations: { | ||
| self.view.transform = CGAffineTransform(translationX: 0, y: translation.y) | ||
| }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아하 !!! 남겨준 글(밑의 코멘트 포함)이랑 블로그 읽어보고 왔습니당
좋은 자료와 설명 감사합니다 쵝오
🌱 작업한 내용
UIPanGestureRecognizer기능 추가완료 버튼누르면 한 번에 넘어가지게 수정하였습니다.background alpha값 자연스럽게 변경closure 사용하여 해결 하였습니다.
🌱 PR Point
UIPanGestureRecognizer기능을 추가 하였습니다.바텀 시트의 주석은 따로 노션이나, 저희 슬랙 또는 블로그에 정리될 때까지는 모르는 부분을 위해 남겨 놓았습니다.‼️
추후 정리가 완료된다면, 삭제할 예정이며 삭제는 제가 진행합니다 ‼‼
추가 질문 언제든 환영합니다~
기능
뒤로 가기 기능
배경색 변하는 기능
활용할 기능
기본 적인 기능 들만 구현 하였고, 추후 수정이 필요할때 마다 누구든지 수정 하면 좋겠습니다.
🍀 교훈
라이브러리가 존재한다면 있는 라이브러리 쓰는게 현명한 방법이 아닐까 생각합니다,, 🥹🥹
흑흙 😭😭
참고 @513sojin
https://github.com/SCENEE/FloatingPanel
📸 스크린샷
RPReplay_Final1701162940.2.MOV
📮 관련 이슈