I have a UIView
subclass named "MyView". In ControllerA, it has a property, MyView *myView
, and added it to self.view
. On myView
, there are some random subviews sliding from right to left, and then disappears. What I want to do is, when the user tap one of the sliding subview, identify that view, and push another controller.
In MyView.m I overrided touchesBegan
, touchesEnded
, touchesCanceled
, and add NSLog in each method. In touchesEnded
methds, I use the code below to identify the subview being tapped:
UITouch *touch = [touches anyObject];
CGPoint touchLoaction = [touch locationInView:self];
for (UIView *subview in self.subviews) {
if ([subview.layer.presentationLayer hitTest:touchLoaction]) {
if (_delegate && [_delegate respondsToSelector:@selector(canvas:didSelectView:)]) {
[_delegate canvas:self didSelectView:subview];
}
break;
}
}
My operation steps are:
When I tap one subview, the log is: began, ended. And then pushed to controllerB.
When I pop back to controllerA, and tap one subview, the log is: began, cancelled, and didn't push to controllerB because touchesEnded didn't get called.
When tap the subview again, the log is: began, ended, and then pushed to controllerB.
I suspect the reason was because of the push, so I commented out the 'identifying' code in touchesEnded
method, now, when I tap a subview, the log is always: began, ended.
So my question is, why touchesEnded
method didn't get called in step 2?
I tried to use performSelector:afterDelay:
to delay the push, but it doesn't help. When I pop back and tap a subview, it is always touchesCancelled
method get called, and then I tap again, then touchesEnded
get called.
Can any one help me with this? Thanks in advance and best wishes!