gpt4 book ai didi

ios - UIButton 触摸 Action 不在触摸时调用但在触摸移动时调用

转载 作者:可可西里 更新时间:2023-11-01 03:05:33 25 4
gpt4 key购买 nike

当用户按下 UIButton 时需要执行一个 Action

[button addTarget:self action:@selector(touchDown:event:) forControlEvents:UIControlEventTouchDown];
[button addTarget:self action:@selector(drag:event:) forControlEvents:UIControlEventTouchDragInside];
[button addTarget:self action:@selector(drag:event:) forControlEvents:UIControlEventTouchDragOutside];
[button addTarget:self action:@selector(touchUp:event:) forControlEvents:UIControlEventTouchUpInside];
[button addTarget:self action:@selector(touchUp:event:) forControlEvents:UIControlEventTouchUpOutside];

- (void)touchDown:(UIButton *)sender event:(UIEvent *)event {
//begin only called when I move my finger
}


- (void)drag:(UIButton *)sender event:(UIEvent *)event {
//called when I move my finger, after touchDown was called
}
- (void)touchUp:(UIButton *)sender event:(UIEvent *)event {

}

我的应用程序的 Root View Controller 是 tabbarviewcontroller,每个选项卡都是一个导航 View Controller 。在聊天场景的 viewWillAppear 方法中,我隐藏了标签栏。

结果是,在设备上,当我向下触摸时,它不会被调用,而当我稍微移动手指时,它会被调用。

注意:

  1. 使用长按手势识别器也不起作用。

  2. 如果我将按钮放在远离标签栏区域的位置,它就可以在设备上运行。

  3. 在模拟器上,一切正常。

我创建了一个示例项目: https://drive.google.com/folderview?id=0B_9_90avvmZtRmRDeHFkbFJLaFk&usp=sharing

最佳答案

这个按钮是否位于 ScrollView (包括集合或表格 View )内的任何位置?如果是这样,那么这正是预期的行为。系统会等待查看您是否要点击按钮或拖动 ScrollView 。来自苹果:

Because a scroll view has no scroll bars, it must know whether a touch signals an intent to scroll versus an intent to track a subview in the content. To make this determination, it temporarily intercepts a touch-down event by starting a timer and, before the timer fires, seeing if the touching finger makes any movement. If the timer fires without a significant change in position, the scroll view sends tracking events to the touched subview of the content view. If the user then drags their finger far enough before the timer elapses, the scroll view cancels any tracking in the subview and performs the scrolling itself. Subclasses can override the touchesShouldBegin:withEvent:inContentView:, pagingEnabled, and touchesShouldCancelInContentView: methods (which are called by the scroll view) to affect how the scroll view handles scrolling gestures.

如果您不想要这种行为,您可以将 parentview.delaysContentTouches 设置为 NO 您可能还需要将 canCancelContentTouches 设置为

关于ios - UIButton 触摸 Action 不在触摸时调用但在触摸移动时调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22285861/

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