首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从UITouch获得UIPanGestureRecognizer

从UITouch获得UIPanGestureRecognizer
EN

Stack Overflow用户
提问于 2014-12-27 22:37:47
回答 2查看 1.4K关注 0票数 2

是否可以通过UITouch获得一个UIPanGestureRecognizer对象?我该怎么做?

EN

回答 2

Stack Overflow用户

发布于 2014-12-27 23:19:26

作为苹果公司的文件说没有一个属性来获取UIGestureRecognizer对象中的touch。但是您可以子类UIGestureRecognizer类,以便重写touchesBegan:withEvent:touchesMoved:withEvent:touchesEnded:withEvent:等,从而检索UITouch对象。

如果可以有用,也可以查看locationOfTouch:inView:

干杯!

票数 1
EN

Stack Overflow用户

发布于 2014-12-28 00:12:18

我解决了这个问题:

PanGestureRecognizer.h文件

代码语言:javascript
复制
#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;


@end

PanGestureRecognizer.m文件

代码语言:javascript
复制
#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];
    }

}

@end

GestureView.m文件

代码语言:javascript
复制
- (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{

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27672095

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档