iPhone SDK,如何让按钮响应双击?

发布于 2024-11-28 23:42:27 字数 56 浏览 0 评论 0原文

在我的 iPhone 应用程序中,我有按钮,我应该让它们响应双击。

我该怎么做呢?

In my iphone app, I've got buttons and I should make them respond to a double click.

How should I do that?

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

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

发布评论

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

评论(4

绿光 2024-12-05 23:42:27

您必须

在 initWithFrame 中使用 UIGestures (如果您使用 Interface Builder,则必须在 initWithCoder 中使用)

   UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
    doubleTap.numberOfTapsRequired = 2;
    [self addGestureRecognizer:doubleTap];

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
    singleTap.numberOfTapsRequired = 1;
    [self addGestureRecognizer:singleTap];
    [singleTap requireGestureRecognizerToFail:doubleTap];

    [doubleTap release];
    [singleTap release];

然后添加方法

- (void) doubleTap: (UITapGestureRecognizer *) sender
{

     do whatever
}

- (void) singleTap:(UITapGestureRecognizer *)sender
{

}

You have to use UIGestures

In the initWithFrame (or initWithCoder if you're using Interface Builder)

   UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
    doubleTap.numberOfTapsRequired = 2;
    [self addGestureRecognizer:doubleTap];

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
    singleTap.numberOfTapsRequired = 1;
    [self addGestureRecognizer:singleTap];
    [singleTap requireGestureRecognizerToFail:doubleTap];

    [doubleTap release];
    [singleTap release];

Then add the methods

- (void) doubleTap: (UITapGestureRecognizer *) sender
{

     do whatever
}

- (void) singleTap:(UITapGestureRecognizer *)sender
{

}
花之痕靓丽 2024-12-05 23:42:27

你需要使用手势,试试这个 -

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
    [doubleTap setNumberOfTapsRequired:2];
    [doubleTap setNumberOfTouchesRequired:1];
    [yourView addGestureRecognizer:doubleTap];
    [doubleTap release];

You need to use gestures, Try this -

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
    [doubleTap setNumberOfTapsRequired:2];
    [doubleTap setNumberOfTouchesRequired:1];
    [yourView addGestureRecognizer:doubleTap];
    [doubleTap release];
悍妇囚夫 2024-12-05 23:42:27

尝试在按钮定义中添加以下内容:-

[button addTarget:self action:@selector(buttontappedtwice)     forControlEvents:UIControlEventTouchDownRepeat];

其中,buttontappedtwice 是一个方法,当您点击此特定按钮两次时将调用该方法...干杯

Try adding following to button defination :-

[button addTarget:self action:@selector(buttontappedtwice)     forControlEvents:UIControlEventTouchDownRepeat];

where buttontappedtwice is a method which will be called when u tap this particular button twice... Cheers

总以为 2024-12-05 23:42:27

试试这个。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     UITouch *touch = [[event allTouches] anyObject];
     if (touch.tapCount == 2) {
     }
}

Try this.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
     UITouch *touch = [[event allTouches] anyObject];
     if (touch.tapCount == 2) {
     }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文