3

I have a UIView containing a UIScrollView. This UIView is supposed to respond to some touch events but it is not responding because of the scrollView it contains.

This scrollView's contentView is set to a MoviePlayer inside the OuterView. Now whenever I click in the area where the MoviePlayer is, touch events of my OuterView are not responding.

I have even set the movie player's userInteraction to NO.

but now scrollView is interfering it seems.

I have referred to this post on SO itself.

How can a superview interecept a touch sequence before any of its subviews?

But the solution there, asks me to set the userInteractionEnabled to NO for the scrollView But if I do so, my pinch zoom doesn't take place either!

What to do?

Community
  • 1
  • 1
Amogh Talpallikar
  • 12,084
  • 13
  • 79
  • 135

1 Answers1

0

An UIScrollView intercepts all touch events because it has to decide if/when the user has movd their finger in order to scroll the scroll view. You may want to subclass UIView, then in the

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)evt;
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)evt;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)evt;

methods, check for the neccessary touches, then forward all these methods to your UIScrollViewInstance. For example:

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface MyView: UIView {
    UIScrollView *scrollView;
}

@end

@implementation MyView

/* don't forget to alloc init your ScrollView init -init
   and release it in -dealloc! Then add it as a subview of self. */

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)evt
{
    /* check for a gesture */
    [scrollView touchesBegan:touches withEvent:evt];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)evt;
{
    /* check for a gesture */
    [scrollView touchesMoved:touches withEvent:evt];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)evt;
{
    /* check for a gesture */
    [scrollView touchesEnded:touches withEvent:evt];
}

@end
  • I would definitely check for this solution but meanwhile I was trying to subclass the ScrollView and overriding the hitTest and checking for tapCount. if its 1, return the superview otherwise self. But can You tell me why is the tapCount coming out to be zero ? – Amogh Talpallikar Jan 30 '12 at 13:00