2013-01-21 3 views
4

UIScrollView 하위 뷰를 화면상의 위치에 따라 변경해야합니다. 그러면 하위로 이동하면서 더 작아지고 아래로 이동하면서 더 커질 수 있습니다.픽셀 단위로 UIScrollView 동작 인식하기

모든 픽셀의 변화로 contentOffset을 알 수있는 방법이 있습니까? 나는 scrollViewDidScroll: 방법을 잡았지만, 움직임이 빠를 때마다 두 번의 호출간에 200pxls의 변화가있을 수 있습니다.

아이디어가 있으십니까?

+0

스크롤 뷰로 모든 픽셀을 제공 할 수 없기 때문에 '점프'를 처리해야합니다. 이벤트 루프보다 스크롤 속도가 빠르다고 생각하면 항상 1보다 큰 오프셋 변경이 발생합니다. –

+0

정말 UIScrollView를 원하십니까? UIView만으로도 충분합니다. UIVIew에서 @ sergio의 대답을 사용하십시오. – folex

답변

3

당신은 기본적으로 두 가지 방법이 있습니다

  1. 서브 클래스 UIScrollViewtouchesBegan/Moved/Ended를 오버라이드 (override)를;

  2. 현재 UIScrollViewUIPanGestureRecognizer을 추가하십시오.

  3. 타이머를 설정하고 타이머가 발생할 때마다 _scrollview.contentOffset.x; 첫 번째 경우에

, 당신은 터치 처리 방법을 위해 할 것입니다 :

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { 

UITouch* touch = [touches anyObject]; 
    _initialLocation = [touch locationInView:self.view]; 
    _initialTime = touch.timestamp; 

    <more processing here> 

    //-- this will make the touch be processed as if your own logics were not there 
    [super touchesBegan:touches withEvent:event]; 
} 

난 당신이 touchesMoved을 위해 그렇게 할 필요가 확신; 제스처가 시작되거나 끝날 때 특정 무언가를 필요로하는지 여부를 모릅니다. 이 경우에도 touchesMoved:touchesEnded:을 무시하십시오. touchesCancelled:에 대해서도 생각해보십시오. 세 번째 경우는 구현 될 꽤 간단하다

//-- add somewhere the gesture recognizer to the scroll view 
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panView:)]; 
panRecognizer.delegate = self; 
[scrollView addGestureRecognizer:panRecognizer]; 

//-- define this delegate method inside the same class to make both your gesture 
//-- recognizer and UIScrollView's own work together 
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer 
{ 
    return TRUE; 
} 

:

두 번째 경우에, 당신은 뭔가를 할 것입니다. 다른 두 가지 결과가 더 좋은 결과를 가져올 지 확신 할 수 없습니다.

+1

이 메서드는 모든 픽셀 변경시에도 호출되지 않습니다. 빠른 손가락 움직임은 두 번의 호출간에 큰 변화를 가져옵니다. –

+1

@Jonathan Cichon : 당신은 그면에서 맞습니다. 타이머를 사용하여 세 번째 방법을 추가했지만 픽셀 완벽 검색을 무효화 할만큼 빠른 움직임이 항상있을 것입니다. – sergio

+1

제 3의 방법이 더 나은 결과를 얻지 못할 것이라고 생각합니다. 저는 몇 시간 전에 uiscrollview에서 키 - 값 - 관측을 사용했고, kvo는 정확히 'scrollViewDidScroll :'처럼 정확하게 호출되었습니다. 그래서 위임을 호출 할 때 이제까지 재산은 변화한다. –

관련 문제