【问题标题】:How to Better Drag a UIButton? UIButton UIControlEventTouchUpInside Event Is Not Called如何更好地拖动 UIButton?未调用 UIButton UIControlEventTouchUpInside 事件
【发布时间】:2013-04-08 20:25:24
【问题描述】:

我的可拖动按钮正在使用这些事件进行拖动:

[button addTarget:self action:@selector(beganDragging:)
                     forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(wasDragged:withEvent:)
                     forControlEvents:UIControlEventTouchDragOutside | UIControlEventTouchDragInside];
[button addTarget:self action:@selector(exitDragging:)
                     forControlEvents:UIControlEventTouchUpInside];

上面是直截了当的。方法wasDragged 将 UIButton 的中心调整到 UITouch 位置。但是,在某些情况下,我最终会挂起按钮(通常在手指释放后它会捕捉到网格),因为从未调用过 UIControlEventTouchUpInside

怎么样?假设我开始拖动一个按钮,并在按住它的同时制作屏幕截图(Power+Home)。当我释放按钮时,不会调用任何事件(即UIControlEventTouchUpInside)。因此,我的按钮被卡住并且没有捕捉到方法exitDragging中的网格

如何确保exitDragging 始终运行?

【问题讨论】:

    标签: iphone ios objective-c uiview uitouch


    【解决方案1】:

    也许使用带有touchesBegantouchesEnded 等的 UIView API 会更容易。

    看来您无论如何都没有使用 UIButton 功能。我认为使用 UIButton 的目标机制管理拖动并不是它的本意。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      相关资源
      最近更新 更多