Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have several UIButtons which I use to set the current action when tapping in the main area. I would also like to allow the user to drag from the button directly into the main area and take the same action; essentially, the touchesBegan and touchesMoved should be passed on to the main view when touching the UIButtons, but also should send the button press action.

Right now, I have the touch up inside changing the control. The drag exit calls the touch up inside section to set the control, then calls the touches began section to start the main area touching operation.

However, at this point, the touchesMoved and touchesEnded are obviously not being called, because the touches originated on the UIButton.

Is there a way to half-ignore the touches so they're passed to the main area, but also allow me to set the control first?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
777 views
Welcome To Ask or Share your Answers For Others

1 Answer

I know this question is two years old (and already answered), but nevertheless...

When I tried this myself, the touches were forwarded, but the buttons no longer behaved like buttons. I also passed the touches along to "super" and now all is well.

So, for beginners that might stumble upon this, this is what the code should look like:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  
    [super touchesBegan:touches withEvent:event];
    [self.nextResponder touchesBegan:touches withEvent:event]; 
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...