Changing UIView Touchscreen Behavior Using Xcode 4.2?

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

+6
source share
2 answers

I tried to track a similar problem in the last few hours. Finally managed to solve this problem with this message

Actually, it seems like I just managed to solve this using the hint https://devforums.apple.com/message/519690#519690
I used to just redirect the touchesEnded event to self.nextResponder. When I added touchsBegan, Moved, Canceled handlers with similar implementations like touchsEnded, the event seems to bubble up to the root view of the controller.
So, I think, on iOS5, views turned off touchEnded events when they didn't see Began's corresponding touches.

I did not need to add Moved / etc., I just redirected TouchesBegan and then TouchesEnded started working again!

+5
source

Some touch processing made a chance in iOS 5.0; especially if you re-linked the application with the 5.0 SDK.

UIView touch processing methods are described here that say the following:

If you override this method without calling super (general usage pattern), you should also override other methods for handling touch events, if only as executable files (empy).

So, if you do this, you need to do everything. I know that UIKit has begun to take steps to make sure it was in 5.0.

So, I would start there - override all the methods in your view and see what happens.

+2
source

Source: https://habr.com/ru/post/899411/


All Articles