IOS 5: UIScrollView not pass touches to nextRespon

2019-07-13 12:27发布

问题:

I have a subclass of UIScrollView, and override all 4 Touches functions for it. In those Touches functions, [[self nextResponder] Touches...] and [super Touches...] are used to pass the touches events.

Also I have a view controller in which I override all 4 Touches functions too. In the Controller, I set the self.view as: self.view = subclass of UIScrollview;

Before iOS 5, when there are touches move on the scrollview, the view controller's touch functions can receive all touch begin/move/end/cancel calls. But in iOS 5, they can't, only one touchesBegan and one touchesMove are received.

From the log of the code, touch functions in the UIScrollView's subclass are always called.

Also, If I set the subclass.enableUserInteraction=NO, the touches function in view controller will be called well. But I need the scrollview to have interaction with user, so I can't set it to no.

Is there anything different I missed in iOS 5? Thank you in advance.

回答1:

There is a very simple work around :)

Instead of:

[self.nextResponder touchesMoved:touches withEvent:event];

Use:

[[self.nextResponder nextResponder] touchesMoved:touches withEvent:event];

Works also for touchesBegan & touchesEnded.

That's it! Problem gone! Now the touches events are passed to the next responder :)



回答2:

Looks like an iOS 5 bug. See this SO post:

touchesMoved not firing in iOS5 for the iPhone for UIScrollView

"As mentioned before I logged a defect with Apple, they finally got back to me. And I quote: 'After further investigation it has been determined that this is a known issue, which is currently being investigated by engineering.". They give the original bug ID #10213937. They give thanks for submitting the bug, but do not offer any workarounds.'"

Still not sure how to solve for iOS 5 unfortunately.