开发者

Not receiving touchesEnded/Moved/Cancelled after adding subView

开发者 https://www.devze.com 2022-12-24 01:20 出处:网络
Title more or less says it all.In response to a touchesBegan event, my UIViewController recolours itself and adds some subviews.

Title more or less says it all. In response to a touchesBegan event, my UIViewController recolours itself and adds some subviews.

It never receives the touchesEnded. I guess 开发者_开发百科because the added subviews are somehow intercepting the event. I tried calling resignFirstResponder on the subviews to no avail.

The code works fine when I don't add the child views and the touch events are called as normal.

Any ideas?

Thanks

EDIT: Bit of detail and how I fixed it.

Basically I had a master view with some subviews, when I touched the subview, the event would be passed through to the master view, however, on this event I was removing the subviews and adding new ones in their place. The fact that the touch originated on a subview which no longer existed meant that the rest of the touch was lost.

I fixed this by overriding hitTest:withEvent in my master view, to stop touches ever getting tested against the subviews


Did you try to set the userInteractionEnabled property to NO for the subview before adding it as a subview ?


You're going to need pass the touch from the subview onto the superview using something like this:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    [super touchesBegan:touches withEvent:event];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消