【问题标题】:using touch.tapCount to determine a longpress on a button使用 touch.tapCount 确定按钮上的长按
【发布时间】:2014-08-05 20:01:51
【问题描述】:

我正在做的事情在模拟器和我的 iPad2 上都有效,我没有遇到任何问题,但这不是记录在案的做事方式,所以我担心它可能不适用于较新的 iPad。

我有 UIButtons 可以区分触摸和长按。

按钮的构造与往常一样,有目标和动作,没有手势。

- (IBAction)buttonAction:(id)sender forEvent:(UIEvent*)event
{
  UIButton *button=(UIButton *)sender;

  bool longpress=NO;
  UITouch *touch=[[[event allTouches] allObjects] objectAtIndex:0];
  if(touch.tapCount==0) longpress=YES;

  switch(button.tag)
  {
    case TAG:
    {
        if(longpress)
        {
              ... do longpress thing
        }
        else
        {
              ... do regular touch thing
        }
        break;
    }
    ...
  }
}

【问题讨论】:

    标签: ios objective-c uibutton long-press


    【解决方案1】:

    为什么不创建一个UILongPressGestureRecognizer 并将其添加到按钮中。这是识别此类行为的首选方式。

    【讨论】:

    • 我正在做的工作,代码很简单。我想知道它是否适用于所有人,或者是否有其他人这样做过。
    猜你喜欢
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多