使用 UIGestureRecognizer 子类双击某些特定子视图?

发布于 2024-10-04 15:52:16 字数 723 浏览 8 评论 0原文

我按照 121 WWDC 2010(高级手势识别)的会议演示找到了一种方法,可以在另一个类(TransformGestureReconizer)上实现所有行为(旋转、缩放、平移),并且一切顺利,并对子视图执行此操作

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:baseView];
    subView1.userInteractionEnabled = YES;
    [self addTransformGestureToView:subView1];
}

:我的问题: 我想在双击所需的子视图时执行操作。

因此,如果我添加:

- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer

我无法选择我的操作提供的视图(例如更改其上的图像) 如果我在主视图上添加:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

我只能处理主视图上的双击,但不能处理子视图,并且只能在 TransformGestureReconizer.h 上执行此操作,但不能选择点击的视图(我认为是因为 UIGestureRecognizer 的子类)。

I followed the session's demo of the 121 WWDC 2010 (Advanced Gesture Recognition) to find a way to have all behaviors (rotate, scale, translate) on an other class (TransformGestureReconizer) and all goes well and do this for the subviews:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:baseView];
    subView1.userInteractionEnabled = YES;
    [self addTransformGestureToView:subView1];
}

Here is my problem :
I would like to have an action when I double tap on a desired subview.

So If I add a :

- (void)handleDoubleTap:(UIGestureRecognizer *)gestureRecognizer

I can't choose which view my action delivers (like changing the image on it)
If I add on the main view:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

I can only handle the double tap on the main view, but not for the subviews and can only do it on the TransformGestureReconizer.h but then not choose the view tapped ( I think because subclass of UIGestureRecognizer).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

早乙女 2024-10-11 15:52:16

我找到了一个解决方案:

    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[self addTransformGestureToView:subView1];
[self.subView1 addGestureRecognizer:doubleTap];
[doubleTap release];

I found a solution :

    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired:2];
[self addTransformGestureToView:subView1];
[self.subView1 addGestureRecognizer:doubleTap];
[doubleTap release];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文