ドキュメントでチェックマーク ジェスチャ レコグナイザーの例を使用しようとしていますが、初めてジェスチャを作成したときにのみ機能します。それを認識した後、それは再び動作しません。
私は次のコードを使用しています:
CheckmarkGestureRecognizer.h
#import <UIKit/UIKit.h>
#import <UIKit/UIGestureRecognizerSubclass.h>
@interface Checkmark2GestureRecognizer : UIGestureRecognizer {
BOOL strokeUp ;
}
- (void)reset;
- (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;
@property (nonatomic,readwrite) UIGestureRecognizerState state;
@property (nonatomic,assign) CGPoint midPoint;
@end
CheckmarkGestureRecognizer.m
#import "Checkmark2GestureRecognizer.h"
@implementation Checkmark2GestureRecognizer
@synthesize state;
@synthesize midPoint;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
NSLog(@"began");
strokeUp = NO;
if ([touches count] != 1) {
self.state = UIGestureRecognizerStateFailed;
return;
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
if (self.state == UIGestureRecognizerStateFailed) return;
CGPoint nowPoint = [[touches anyObject] locationInView:self.view];
CGPoint prevPoint = [[touches anyObject] previousLocationInView:self.view];
if (!strokeUp) {
// on downstroke, both x and y increase in positive direction
if (nowPoint.x >= prevPoint.x && nowPoint.y >= prevPoint.y) {
self.midPoint = nowPoint;
// upstroke has increasing x value but decreasing y value
} else if (nowPoint.x >= prevPoint.x && nowPoint.y <= prevPoint.y) {
strokeUp = YES;
} else {
self.state = UIGestureRecognizerStateFailed;
}
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
if ((self.state == UIGestureRecognizerStatePossible) && strokeUp) {
self.state = UIGestureRecognizerStateRecognized;
NSLog(@"Ended");
}
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesCancelled:touches withEvent:event];
self.midPoint = CGPointZero;
strokeUp = NO;
self.state = UIGestureRecognizerStateFailed;
NSLog(@"cancelled");
}
- (void)reset {
[super reset];
NSLog(@"reset");
self.midPoint = CGPointZero;
strokeUp = NO;
}
@end
私が間違っていることについて何か考えはありますか?
ありがとう