간단한 질문은 : 사용자가 iPhone 화면에서 손가락을 스 와이프하면 어떻게 감지 할 수 있습니까?iPhone에서 사용자가 스 와이프를 처리합니다.
1
A
답변
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
}
}
이렇게하면 스 와이프 인식기를 구현할 수 있습니다. 또한, 당신은 정말이 주제에 대한 문서를 체크 아웃해야합니다 :
3
UIGestureRecognizer는 사용자가 원하는 것입니다. 특히 UISwipeGestureRecognizer 하위 클래스
0
를 아, 나는 내 자신의 질문에 대답 할 수 있었다 : 도움말 모두 http://developer.apple.com/library/ios/#samplecode/SimpleGestureRecognizers/Introduction/Intro.html#//apple_ref/doc/uid/DTS40009460
감사합니다!
kMinimumVariance를 설명하지 않았습니다. – Moshe
나는 편집했다, Moshe. –