簡體   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