iOS:UISwipeGestureRecognizer

发布于 2024-12-24 01:32:59 字数 423 浏览 1 评论 0原文

我有这样的代码:

UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
[recognizer setNumberOfTouchesRequired:1];
[n16 addGestureRecognizer:recognizer];
[n17 addGestureRecognizer:recognizer];

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{
NSLog(@"SWIPE");
}

我怎样才能知道什么视图发生了手势?视图为 n16 和 n17

I have this code:

UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipeHandle:)];
[recognizer setNumberOfTouchesRequired:1];
[n16 addGestureRecognizer:recognizer];
[n17 addGestureRecognizer:recognizer];

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{
NSLog(@"SWIPE");
}

How can I know what view happens gesture? views are n16 and n17

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

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

发布评论

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

评论(2

幼儿园老大 2024-12-31 01:32:59

我不确定您是否可以将相同的 UIGestureRecognizer 实例注册到不同的视图,但如果可以,我认为 UIGestureRecognizer.view 属性就是您正在寻找的。

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIGestureRecognizer

所以,你应该能够做这样的事情。 (同样,我不确定您是否可以将不同的 UIGestureRecognizer 实例附加到不同的视图......)

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{
    if(gestureRecognizer.view == n16)
    {
        // specific operation to n16
    } 
    else if(gestureRecognizer.view == n17)
    {
        // specific operation to n17
    }
}

I am not sure if you can register the same UIGestureRecognizer instance to different views, but if you could, I think UIGestureRecognizer.view property is what you are looking for.

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIGestureRecognizer_Class/Reference/Reference.html#//apple_ref/occ/cl/UIGestureRecognizer

So, you should be able to do something like this. (again, I am not sure if you can attach different UIGestureRecognizer instance to different views...)

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer{
    if(gestureRecognizer.view == n16)
    {
        // specific operation to n16
    } 
    else if(gestureRecognizer.view == n17)
    {
        // specific operation to n17
    }
}
苍暮颜 2024-12-31 01:32:59

像这样:

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer {
    NSLog(@"SWIPE");
    UIView *vw = [gestureRecognizer view]; // this is the view that generated the
        // gesture - either n16 or n17
}

Like this:

- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer {
    NSLog(@"SWIPE");
    UIView *vw = [gestureRecognizer view]; // this is the view that generated the
        // gesture - either n16 or n17
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文