0

화면 경계에서 스 와이프 한 경우에만 UIScrollView를 스크롤 할 수있게하려고합니다. 스 와이프 제스처 인식기를 사용하고 있습니다. 위의 코드와 여기 UISwipeGestureRecognizer에서 특정 CGPoint에 대해 UIScrollView 스크롤 사용

내 코드입니다

-(void)swipeHandlerLeft:(UISwipeGestureRecognizer *)swipeRecognizer 
{ 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 

    point = [swipeRecognizer locationInView:self.view]; 

    if(swipeRecognizer.direction == UISwipeGestureRecognizerDirectionLeft) 
    { 
     if (point.x > screenWidth - 10) 
     { 
      NSLog(@"Swipped Left"); 
      _scrollView.scrollEnabled = YES; 
     } 
     else 
     { 
      _scrollView.scrollEnabled = NO; 
     } 
    } 

} 

-(void)swipeHandlerRight:(UISwipeGestureRecognizer *)swipeRecognizer 
{ 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 

    point = [swipeRecognizer locationInView:self.view]; 

    if(swipeRecognizer.direction == UISwipeGestureRecognizerDirectionRight) 
    { 
     if (point.x < 10) 
     { 
      NSLog(@"Swipped Right"); 
      _scrollView.scrollEnabled = YES; 
     } 
     else 
     { 
      _scrollView.scrollEnabled = NO; 
     } 
    }  
} 

문제가있는 ScrollView는 사용할 수 없습니다 때까지 작동,하지만이 활성화되면이 방법은 호출되지 않아요 그리고 난 그 이유는 내가 '으로 생각 내 UIView 내에서 scrollview를 추가했습니다.

어떤 도움을 주시면 감사하겠습니다.

답변

0

UIScrollView에는 이미 UIGestureRecognizer가 있습니다. gestureRecognizers에 코드를 연결해야한다고 생각합니다. myScrollView.panGestureRecognizermyScrollView.pinchGestureRecognizer에 액세스 할 수 있습니다.

+0

불편을 끼쳐 드려 죄송합니다. 작은 데모 코드로 아이디어를 표현해주십시오. – Vaibhav

0

스 와이프보기 전에 scrollview가 사용자의 터치를 포착합니다. 스 와이프 제스처 인식기가 스크롤 뷰의 수퍼 뷰에 있다고 가정합니다.

scrollView 팬 제스처 인식기에서 requireGestureRecognizerToFail(_:) 을 호출하고 스 와이프 제스처를 전달하여 종속성을 만들어야합니다.