繁体   English   中英

如何在UIView Gesture下检测UIButton的TouchUp事件

[英]how do i detect UIButton's TouchUp event under UIView Gesture

我有多个按钮,并将它们添加到UIView中。 我已将TouchDown / TouchUp事件添加到所有按钮。 到目前为止,一切都非常简单且完美无缺

但现在我的要求是,我想在视图上滑动,而在滑动时,我想在滑动下检测到相同的TouchDown / TouchUp事件。 (例如,在按钮的触地得分时,我将更改按钮的突出显示图像,在触摸时将其恢复为正常图像)

可能吗?

我怎么能做到呢?

您是否特别需要滑动手势?

有一种方法可以检测手指何时滑过UIView:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;

也许您可以创建一个继承自UIButton的类并添加touchesMoved方法:

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
   // psuedo code
   [self setBackgroundImageForControlState:@"file.png"];
}

然后,在touched Ended方法中,可以在以下位置交换不同的图像:

// when finger is raised off the button
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
   // psuedo code
   [self setBackgroundImageForControlState:@"file.png"];
}

也许您应该像UIControlEventTouchDragEnterUIControlEventTouchDragExit这样的小事件? 不能确定,但​​这似乎是一个解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM