|
Q: My view is displayed correctly on the screen, but does not receive any touch events. Why is that?A: The most common cause of this problem is because your view is located outside the bounds of its parent view. When your application receives a touch event, a hit-testing process is initiated to determine which view should receive the event. The process starts with the root of the view hierarchy, typically the application's window, and searches through the subviews in front to back order until it finds the frontmost view under the touch. That view becomes the hit-test view and receives the touch event. Each view involved in this process first tests if the event location is within its bounds. Only after the test is successful, does the view pass the event to the subviews for further hit-testing. So if your view is under the touch but located outside its parent view's bounds, the parent view will fail to test the event location and won't pass the touch event to your view. One solution to this problem is to modify the layout of the view hierarchy so that your view is inside the bounds of its parent view. If for some reasons the existing layout has to be maintained, you can change the hit-testing behavior of the parent view so that it doesn't ignore the touch events. This can be done by overriding the -( - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { // Convert the point to the target view's coordinate system. // The target view isn't necessarily the immediate subview CGPoint pointForTargetView = [self.targetView convertPoint:point fromView:self]; if (CGRectContainsPoint(self.targetView.bounds, pointForTargetView)) { // The target view may have its view hierarchy, // so call its hitTest method to return the right hit-test view return [self.targetView hitTest:pointForTargetView withEvent:event]; } return [super hitTest:point withEvent:event]; } For more information about hit-testing, please refer to the discussion on Event Delivery in Event Handling Guide for iOS. Other possible causes of this problem include:
You should make sure the If your view doesn’t receive touch events during animation, it is because the animation methods of Document Revision History
|