是否可以通过UITouch获得一个UIPanGestureRecognizer对象?我该怎么做?
发布于 2014-12-27 23:19:26
作为苹果公司的文件说,没有一个属性来获取UIGestureRecognizer对象中的touch。但是您可以子类UIGestureRecognizer类,以便重写touchesBegan:withEvent:、touchesMoved:withEvent:、touchesEnded:withEvent:等,从而检索UITouch对象。
如果可以有用,也可以查看locationOfTouch:inView:。
干杯!
发布于 2014-12-28 00:12:18
我解决了这个问题:
PanGestureRecognizer.h文件
#import <UIKit/UIKit.h>
#import <UIKit/UIGestureRecognizerSubclass.h>
@interface PanGestureRecognizer : UIPanGestureRecognizer {
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
@end
@protocol PanGestureRecognizer <UIGestureRecognizerDelegate>
- (void) panGestureRecognizer:(UIPanGestureRecognizer *)gr movedWithTouches:(NSSet*)touches andEvent:(UIEvent *)event;
@endPanGestureRecognizer.m文件
#import "PanGestureRecognizer.h"
@implementation PanGestureRecognizer
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
if ([self.delegate respondsToSelector:@selector(panGestureRecognizer:movedWithTouches:andEvent:)]) {
[(id)self.delegate panGestureRecognizer:self movedWithTouches:touches andEvent:event];
}
}
@endGestureView.m文件
- (void)awakeFromNib {
PanGestureRecognizer *panRecognizer = [[PanGestureRecognizer alloc] initWithTarget:self action:@selector(panRecognition:)];
panRecognizer.maximumNumberOfTouches = 1;
[panRecognizer setDelaysTouchesBegan:NO];
[panRecognizer setDelaysTouchesEnded:NO];
[panRecognizer setCancelsTouchesInView:NO];
panRecognizer.delegate = self;
[self.keyboardLayoutView addGestureRecognizer:panRecognizer];
}
- (void)panGestureRecognizer:(UIPanGestureRecognizer *)panRecognizer movedWithTouches:(NSSet*)touches andEvent:(UIEvent *)event{
}https://stackoverflow.com/questions/27672095
复制相似问题