I upgraded my iPad to 5.0 a couple of days ago and at the same time upgraded Xcode to 4.2 to continue testing my applications. Now I am having problems with touch code in several applications that worked with previous versions of Xcode.
I have subclassed UIImageView to add some drag and drop functionality by overriding -(void)TouchesBegan
and -(void)TouchesMoved
. I did not override -(void)TouchesEnded
in a subclass, but handled this in the view controller for the view containing the image view.
I subclassed UIImageView
in a new project for testing and narrowed the problem down to the point where the parent UIView
(the template created by Xcode) does not seem to send touch events to the view controller (also created by Xcode).
If I add this to my subclass:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touches ended event in ImageToDrag"); [self.nextResponder touchesEnded:touches withEvent:event]; }
and this is for my parent view view controller:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touches ended event in ViewController"); }
when I drop the image that I am moving around the screen, I get a "touches ended event in ImageToDrag"
, but not a log from the view controller.
However, if I intentionally skipped a view by doing this in a subclass view:
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touches ended event in ImageToDrag"); [[self.nextResponder nextResponder] touchesEnded:touches withEvent:event]; }
then I get both log entries.
The only explanation I can come up with is that for some reason, the UIView
consumes the touchesEnded
event and does not pass it to the view controller.
I checked that exclusiveTouch
set to NO
and userInteractionEnabled
set to YES
in the parent view and subclass of UIImageView
.
I also tested compiling for iOS 5.0 and iOS 4.2 and deploying a test application for the iPad iOS 5 iPad and iOS 4.3.1.
The only way I was able to get a touch event on the viewController
is to skip the view and use the double subclass nextResponder
in the subclass. Although this method works, it seems hacked to me, and I'm sure it will come back to bite me later.
Has anyone else seen this behavior? Is there a way to find out what UIView
doing with my touch events?
Thanks Dan