2015-01-07 3 views
3

하나의 셀이 전체 화면 너비를 차지하는 collectionView에서 왼쪽 또는 오른쪽으로 스 와이프 한 것을 감지하고 싶습니다. 제스처 인식기를 추가하지 않고도 수행 할 수 있습니까? 제스처 인식기를 추가하려고 시도했지만 collectionView의 scrollEnabled 속성을 NO로 설정 한 경우에만 작동합니다.UICollectionView Swipe

UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeRight:)]; 
swipeRight.delegate = self; 
swipeRight.numberOfTouchesRequired = 1; 
[swipeRight setDirection:UISwipeGestureRecognizerDirectionRight]; 

UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipeLeft:)]; 
swipeLeft.delegate = self; 
swipeLeft.numberOfTouchesRequired = 1; 
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft]; 

[self.collectionView addGestureRecognizer:swipeLeft]; 
[self.collectionView addGestureRecognizer:swipeRight]; 
+0

왜 스 와이프 제스처를 사용 하시겠습니까? –

+0

왼쪽 또는 오른쪽으로 스 와이프 여부를 감지하는 중 일부 처리를 수행하려고합니다. – user694688

+0

컬렉션보기가 세로 또는 가로로 스크롤합니까? 진짜 질문은 컬렉션보기에서 왼쪽/오른쪽으로 스 와이프를 감지하려고하거나 제스처 인식기가 실제로 원하지 않는다는 것입니다. –

답변

1

컬렉션보기가 스크롤보기에서 상속되므로 scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset을 재정의하려고합니다. 이 방법으로 속도 매개 변수를 평가하여 방향을 결정할 수 있어야합니다. 따라서 UIScrollViewDelegate 프로토콜을 구현해야합니다.

0

문제의 컨텍스트를 완전히 이해하고 있는지 확신 할 수 없습니다. 콜렉션 뷰 내에 콜렉션 뷰가 있다는 것을 알았습니다. 외부 콜렉션 뷰는 수직 스크롤을하고 내부 콜렉션 뷰는 수평 스크롤을한다고 가정합니다. 두 컬렉션의 제스처 인식기간에 실패 종속성을 설정해야합니다.

//Data source for your outer collection view 
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView 
        cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    ... 
    UICollectionView* innerCollectionView = ...; 

    [collectionView. panGestureRecognizer requireGestureRecognizerToFail:innerCollectionView. panGestureRecognizer]; 

    ... 
} 

중첩 컬렉션보기에서 이보다 더 많은 일이 발생하면 몇 가지 세부 정보를 제공 할 수 있습니까?

1

collectionview에 스 와이프 제스처를 추가합니다. 그리고 제대로 작동합니다.

그래서 스티븐 존슨이 말했습니다. 셀에 scrollView가있는 것 같습니다. 그래서 제스처를 차단합니다.

2

아마도 userInteraction을 사용 중지했을 수 있습니다. 확인 했니? 그리고 제스처를 클래스의 속성으로 정의하십시오.

self.collectionView.setUserInteractionEnabled=true;