scrollView를 받고있는 collectionView는 베이스와 같이 스크롤을 프로그래밍으로 움직이는게 가능하다
이를 간편하게 만들어둔게 scrollToItem( at,at, animated )
간편해서
indexPath만 따로 만들어두면 곧장 해당 아이템이 있는곳으로 날아갈수있다.
iOS 15 시뮬레이터에서 돌려보던중 해당 기능이 동작하지 않는걸 발견했는데 도저히 이유를 모르겠던중 아래와같은 답변을 찾았다
https://developer.apple.com/forums/thread/663156
UICollectionView scrollToItem brok… | Apple Developer Forums
Hi All Where we have to put this code? self.collectionView.isPagingEnabled = false self.collectionView.scrollToItem(at: indexPath, at: .left, animated: false) self.collectionView.isPagingEnabled = true In my scenario, Let's suppose there are 5 items to sho
developer.apple.com
iOS14에서 나온 문제건만..
iOS15에서도 고쳐지지 않았다
문제가된 경우는
scolltoITem하기전 isPgingEnabled가 true로 설정해둘경우이다
그래서
아래와같이 하면된다.
item번호 11번으로 가는 코드이다.
collectionView.isPagingEnabled = false
collectionView.scrollToItem(at: IndexPath(item: 11, section: 0), at: .centeredHorizontally, animated: true)
collectionView.isPagingEnabled = true
scrollToITem내부 파라미터에대해서는 공식 홈페이지를 보시고...
해당 함수를 호출하기전 paging을 꺼둔다.
그리고 다시킨다
어처구니없는 해결방법이지만 동작을 잘해서 그냥 해당방법으로 가기로 결정했다.
'iOS > swift' 카테고리의 다른 글
private(set) 변수를 외부에서 쓰지못하게 막자 (0) | 2022.05.12 |
---|---|
배열을 그룹별로 분리하기 Dictionary(grouping:, by:) (0) | 2022.04.22 |
돈 자리수 표시하기 (0) | 2022.03.08 |
비밀번호용 텍스트필드가 가려지면서 도중 수정이 가능하려면... (0) | 2022.02.19 |
CollectionView ScrollToItem Error, 이전에는 잘됐는데! (0) | 2022.02.07 |