简体   繁体   中英

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; - 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. But for this solution i have to make my buttons with userInteractionEnabled = false , which means they doesn't support gestures or other events anymore. 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) {
            ...
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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