У меня вопрос .. Я хотел бы сделать свой собственный распознаватель жестов с помощью салфетки и что вы перетаскиваете (или прокручиваете) вниз двумя пальцами, но я не знаю, как это сделать.Как сделать собственный распознаватель жестов?
Это мой код GestureSwipe.h:
#import <UIKit/UIKit.h>
@interface GestureSwipe : UIGestureRecognizer
@property CGPoint startTouchPosition;
@property(nonatomic) NSUInteger numberOfTouchesRequired;
@property(nonatomic) UISwipeGestureRecognizerDirection direction;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;
@end
Это мой код GestureSwipe.m:
#define VERT_SWIPE_DRAG_MAX 7
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *aTouch = [touches anyObject];
// startTouchPosition is a property
self.startTouchPosition = [aTouch locationInView:self.view];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *aTouch = [touches anyObject];
CGPoint currentTouchPosition = [aTouch locationInView:self.view];
// Check if direction of touch is horizontal and long enough
if (fabsf(self.startTouchPosition.y - currentTouchPosition.y) <=
VERT_SWIPE_DRAG_MAX)
{
// If touch appears to be a swipe
if (self.startTouchPosition.y < currentTouchPosition.y) {
[self myProcessDownSwipe:touches withEvent:event];
}
self.startTouchPosition = CGPointZero;
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
self.startTouchPosition = CGPointZero;
}
-(void)myProcessDownSwipe:(NSSet *)touches withEvent:(UIEvent *)event {
}
Как сделать прокрутку двумя пальцами?
Тогда у меня есть другие VC, где признают свой собственный жест:
HelloViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
//newGesture = [[GestureSwipe alloc] init];
newGesture = [[GestureSwipe alloc] initWithTarget:self action:@selector(showImage:)];
newGesture.numberOfTouchesRequired = 2;
}
Вы можете взглянуть на документацию UISwipeGestureRecognizer, вы можете установить количество штрихов, необходимых (так, 2 в данном случае) и направление (вниз) https://developer.apple.com/library/ios/documentation/uikit/reference/UISwipeGestureRecognizer_Class/Reference/Reference.html –
Я видел, что и я использую эти свойства, но я не знаю, где мне нужно использовать эти свойства: '@property (неатомический) номер NSUIntegerOfTouchesRequired; @property (nonatomic) UISwipeGestureRecognizer направление направления; ' – user1911
Вы использовали бы его в самом распознавателе жестов, я добавлю больше деталей в ответ, чтобы включить форматированный код. –