gpt4 book ai didi

ios - 如何让 stepper 和 longpress 共存?

转载 作者:行者123 更新时间:2023-11-29 03:22:58 24 4
gpt4 key购买 nike

我尝试使用长按手势和配置为连续更新的步进器来设置 View 。长按时,不会出现步进器的连续特征。目前,我已禁用长按。我想我不需要它。但为了将来引用,我将如何允许两者共存?

需要明确的是,这是我尝试此操作时屏幕的设置方式。

  • 应用程序是通过一个简单的 View Controller 设置的。
  • 在此 View 中添加了一个 subview (可能是一个 Controller ,但我只是将其设为 UIView)。
  • 此 subview 中添加了多个标签和步进器。
  • 步进器被连接为 socket 和 Action 。
  • 长按识别器已添加到 IB 的主视图中。
  • 为了完整起见,还在 IB 的主视图中添加了点击手势。

按预期点击主视图功能。点击步进器将按预期运行。长按主视图可按预期运行。长按步进器则不会。

我修改了长按调用的代码来检查 subview 的框架,如果触摸位置位于该矩形内则不执行操作,但这没有什么区别。我没有尝试让长按在这种情况下失败,但我想接下来我会尝试一下。编辑:好吧,也许不是。似乎没有一个 API 可以实现这一点。然而,有this kludge ,我不会尝试。

随附的是探查器的屏幕截图,其中包含反向调用树,以便您可以看到每个项目正在被调用。

darkStepped: 是步进器调用的 IBAction。如果步进器是由手势识别器触发的,我难道不希望在调用树中看到手势识别器吗?

Screen shot of stepper showing section called by holding stepper

最佳答案

If the stepper were triggered by a gesture recognizer, wouldn't I expect to see the gesture recognizer in the call tree?

堆栈跟踪显示步进器的 _updateCount 方法是通过计时器调度的。

这可能与步进器具有“自动增量”模式这一事实有关,只要您按住它,它就会以给定的(变化的)速率更新。因此,步进器不是简单地调用 _updateCount,而是设置一个计时器来处理此行为。

无论出于何种原因使用计时器,计时器都会解释为什么您在堆栈跟踪中看不到手势识别器。

在您的情况下,发生的情况是步进器获取触摸、处理它们,并且不将它们转发给与其相连的任何手势识别器。

这可以解释如下,尽管这段代码没有明确提到与 UIStepper 控件相关的长按识别器:

根据 Apple Docs :

Interacting with Other User Interface Controls In iOS 6.0 and later, default control actions prevent overlapping gesture recognizer behavior. For example, the default action for a button is a single tap. If you have a single tap gesture recognizer attached to a button’s parent view, and the user taps the button, then the button’s action method receives the touch event instead of the gesture recognizer. This applies only to gesture recognition that overlaps the default action for a control, which includes:

A single finger single tap on a UIButton, UISwitch, UIStepper, UISegmentedControl, and UIPageControl.

...

If you have a custom subclass of one of these controls and you want to change the default action, attach a gesture recognizer directly to the control instead of to the parent view. Then, the gesture recognizer receives the touch event first. As always, be sure to read the iOS Human Interface Guidelines to ensure that your app offers an intuitive user experience, especially when overriding the default behavior of a standard control.

因此,您似乎可以将手势识别器直接附加到控件(可能您需要子类化 UIStepper 才能工作,我不太确定如何解释最后一段)。希望这不会禁用步进器的基本工作(但也许会)。

关于ios - 如何让 stepper 和 longpress 共存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20847475/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com