2017-03-16 9 views
0

내 tvOS 앱에서 UICollectionView의 스크롤링 변경 사항을 수신하려고합니다.UICollectionView의 handlePan selector를 재정의하는 방법

<UIScrollViewPanGestureRecognizer: 0x101a4c1a0; state = Possible; delaysTouchesEnded = NO; view = <UICollectionView 0x1020c5d00>; target= <(action=handlePan:, target=<UICollectionView 0x1020c5d00>)>> 

로그에, 또는 코드 : 나는 궁금했다

myCollectionView.panGestureRecognizer 

연구 후에, 나는 컬렉션 뷰가 기본적으로 선택 handlePan 그들 사이에서 UIPanGestureRecognizer을 몇 가지 제스처 인식기를받는 것을 발견 내 컨트롤러를 제스처 인식기의 대상으로 추가하거나 handlePan 메서드를 재정의하는 방법이 있습니다. UIGestureRecognizerDelegate 구현을 시도했지만 handlePan 메서드에 액세스 할 수 없습니다. 아마도 컬렉션보기에서 직접 UIPanGestureRecognizer 사용자 정의를 추가해야합니까?

답변

3

UICollectionView는 UIScrollView의 하위 클래스이므로 scrollview 대리자를 추가하여 collectionview에서 스크롤 변경 사항을 감지 할 수 있습니다.

// called on finger up if the user dragged. decelerate is true if it will continue moving afterwards 
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { 

} 

// called when scroll view grinds to a halt 
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { 

} 

스위프트 오브젝티브 C

func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { 

} 

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { 

}