2010-12-06 4 views

답변

3

응용 프로그램에 제스처 인식기를 구현해야합니다. 사용자 인터페이스에서

:

#define kMinimumGestureLength 30 
#define kMaximumVariance 5 
#import <UIKit/UIKit.h> 
@interface *yourView* : UIViewController { 
    CGPoint gestureStartPoint; 
} 
@end 

kMinimumGestureLength는 최소 거리가 슬쩍로 계산하기 전에 여행으로 손가락이다. kMaximumVariance은 손가락이 y 축의 시작점 위로 끝날 수있는 최대 거리 (픽셀 단위)입니다.

는 이제 인터페이스 .xib 파일을 열고 IB에서보기를 선택하고 확인 Multiple Touch이 구현에서 View Attributes.

에서 활성화되어 있는지 확인이 방법을 구현한다.

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
     UITouch *touch = [touches anyObject]; 
     gestureStartPoint = [touch locationInView:self.view]; 
    } 

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{ 
    UITouch *touch = [touches anyObject]; 
    CGPoint currentPosition = [touch locationInView:self.view];  

    CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); 
    CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); 


    if(deltaX >= kMinimumGestureLength && deltaY <= kMaximumVariance){ 
     //do something 
} 
else if(deltaY >= kMinimumGestureLength && deltaX <= kMaximumVariance){ 
     //do something 
    } 
} 

이렇게하면 스 와이프 인식기를 구현할 수 있습니다. 또한, 당신은 정말이 주제에 대한 문서를 체크 아웃해야합니다 :

UISwipeGestureRecognizer

+0

kMinimumVariance를 설명하지 않았습니다. – Moshe

+0

나는 편집했다, Moshe. –

3

UIGestureRecognizer는 사용자가 원하는 것입니다. 특히 UISwipeGestureRecognizer 하위 클래스

관련 문제