Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 리펙토링
- tableView
- uiscrollview
- HIG
- uitableview
- rxswift
- Protocol
- SWIFT
- collectionview
- Clean Code
- combine
- swiftUI
- map
- 애니메이션
- swift documentation
- UICollectionView
- ios
- RxCocoa
- ribs
- UITextView
- 스위프트
- MVVM
- Observable
- clean architecture
- Xcode
- 리팩토링
- Human interface guide
- 클린 코드
- 리펙터링
- Refactoring
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] UITableView, UICollectionView, 스크롤 이동 시키는 방법 본문
iOS 응용 (swift)
[iOS - swift] UITableView, UICollectionView, 스크롤 이동 시키는 방법
jake-kim 2021. 10. 21. 00:04UITableView에서 스크롤 이동
- tableView.scrollToRow(at:at:animated:) 메서드 사용
- UI적인 접근이 필요하므로 main 스레드에서 접근
@IBAction func didTapButton(_ sender: Any) {
DispatchQueue.main.async { [weak self] in
self?.tableView.scrollToRow(at: IndexPath(row: 77, section: 0), at: .bottom, animated: true)
}
}
CollectionView에서 스크롤 이동
- collectionView.scrollToItem(at:at:animated:) 메서드 이용
- main 스레드로 접근
@objc func didTapMoveScrollButton() {
DispatchQueue.main.async { [weak self] in
self?.collectionView.scrollToItem(at: IndexPath(row: 77, section: 0), at: .bottom, animated: true)
}
}
* 전체 소스 코드: https://github.com/JK0369/ExTableView
활용
- 이미지 리스트를 tableView나 collectionView로 조회 > 셀을 탭하여 상세화면에서 가로로 이미지를 스크롤하고난 후 리스트 화면으로 넘어오는 경우, 가로로 이미지를 스크롤한 위치로 자동으로 scroll되어 있는 기능 구현에 사용
* 참고
- scrollToRow(at:at:animated:): https://developer.apple.com/documentation/uikit/uitableview/1614997-scrolltorow
- scrollToItem(at:at:animated:): https://developer.apple.com/documentation/uikit/uicollectionview/1618046-scrolltoitem
'iOS 응용 (swift)' 카테고리의 다른 글
Comments