2

我正在做一个调整,当用户在编辑模式下双击一个图标时会弹出一个警报。我已经尝试过

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

SBIcon然后

{
    %orig;
    UITouch *touch = [touches anyObject];
    if (touch.tapCount == 2 && [[objc_getClass("SBIconController") sharedInstance] isEditing])
    {
        //pop an alert and do stuff
    }
}

但这似乎根本不起作用。谁能告诉我上述有什么问题并提出替代方法来实现这一目标?

编辑:如果重要的话,我正在使用theos。

4

2 回答 2

1

适合您的替代方法

UIControlEventTouchDownRepeat如果您的图标是一个按钮,那么您可以通过添加事件轻松检测双标签

[yourIconButton addTarget:self action:@selector(multipleTap:withEvent:) 
             forControlEvents:UIControlEventTouchDownRepeat];



-(IBAction)multipleTap:(id)sender withEvent:(UIEvent*)event 
{
   UITouch* touch = [[event allTouches] anyObject];
   if (touch.tapCount == 2) {
     // Do all your actions here
   }
}

如果您正在考虑整体视图,请使用 UITapGesture

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
[tap setNumberOfTapsRequired:2];
[yourIconView addGestureRecognizer:tap];


- (void)tapAction:(UIGestureRecognizer *)gestureRecognizer
{
    //Do your action
}
于 2014-01-02T04:50:49.873 回答
1

我会建议你使用 Tap 手势识别器。它更具体并且工作非常准确。

有关更多信息,您可以查看此链接:http: //developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html

于 2012-06-11T04:52:37.887 回答