简体   繁体   English

如何在禁用用户交互的情况下为子视图实现longPressGestureRecognizer?

[英]How implement longPressGestureRecognizer for subview with disabled user interaction?

I need UI like this: 我需要这样的用户界面:

在此处输入图片说明

with 2 buttons (yellow and red) and background view (grey), which will have next behaviour: - highlight button when i press on it; 具有2个按钮(黄色和红色)和背景视图(灰色),将具有下一个行为:-当我按下按钮时将其突出显示; - execute when i release on button; -当我释放按钮时执行; - when i press and move in on button from any other view, button became highlighted (ex: press on grey rect and release on red, or press on yellow and release on red); -当我从任何其他视图中按下并移入按钮时,按钮变为突出显示(例如:按下灰色矩形并释放红色,或者按下黄色并释放红色); - support gestures for buttons (like long press and swipe) -支持按钮手势(例如长按和滑动)

So for solving my problem i found only next way: I redefine for my GrayView touch methods: touchesCancelled , touchesMoved , touchesBegan , and there are i check if current touch position is belong to some rect - i execute appropriate action. 因此,为解决我的问题,我只能找到另一种方法:重新定义我的GrayView触摸方法: touchesCancelledtouchesMovedtouchesBegan ,然后检查当前触摸位置是否属于某个矩形-我执行适当的操作。 But for this solution i have to make my buttons with userInteractionEnabled = false , which means they doesn't support gestures or other events anymore. 但是对于此解决方案,我必须使我的按钮具有userInteractionEnabled = false ,这意味着它们不再支持手势或其他事件。 So if i what to use support it, i have to implement it by myself, what i don't what to do. 因此,如果我要使用什么来支持它,则我必须自己实施,而不是要做什么。

So how can i solve this? 那么我该如何解决呢?

If i understand correctly, you can add the gesture recognizers to the gray view as well. 如果我正确理解,也可以将手势识别器添加到灰色视图。 And when the gesture recognizer fires find which colored view was in the touch area: 当手势识别器触发时,找到触摸区域中的彩色视图:

- (void)tapAction:(UITapGestureRecognizer*)recognizer{
    if(recognizer.state == UIGestureRecognizerStateEnded){
        CGPoint position = [recognizer locationInView:grayView];
        if(CGRectContainsPoint(redView.frame, position) {
            ...
        }
    }
}

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

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