user2558461
user2558461

Reputation: 281

capturing touch on UIScrollView

I've tried using the PageViewerViewController in order to pass through few pages in scrollMode. Like another question here in SO (I can't seem to find it tough) I want to capture the touch. so on viewDidLoad I searched through the Views in that controller and found the scrollView and just added a TapGestureRecognizer and it didn't work that well so I added self as its delegate and told him to work simultaneously with other GestureRecognizers and than it worked fine. The thing is, when I try to click on a UIButton on one of the pages, it doesn't recognize the click. and when I set the work simultaneously to off, it suddenly works fine. What am I doing wrong?
More Info: I think I went all over the web with the following problem, and tried to write the code from scratch, tried to change the code, and adding another TapGestureRecognizer so far has the best outcomes.

I'm currently out of any ideas. Any advice is appreciated. Thank you.

For more clarification, I'm trying to captrue all touchStarted, touchMoved, touchEnded on UIPageViewerViewController in ScrollMode. I tried adding another UITapGestureRecognizer to the inner UIScrollView, to the superview of UIScrollView, to self.view of which the UIPageViewerViewController is added on. and when I remove the working simultanously my UITapGestureRecognizer stops working randomly. When I set the working simultanously to work, I'm not able to click any UIButton until I start another UIViewController. and then for some reason, it does work.

Edit I'm only using 3 pages, is UIScrollView better?

I changed everything to just a UIScrollView, when I remove the UITapGesureRecognizer, everything works fine, I receive touches, and everything runs smoothly.

Is there any other way than UITapGestureRecognizer added to UIScrollView to capture touch?

Upvotes: 1

Views: 309

Answers (2)

Putz1103
Putz1103

Reputation: 6211

I think for what you are looking for a UIView would be better than a UIScrollView. If you want to get all the touch events anyway then you can just implement your own scrollview functionality. You can do the paging in onTouchEnded: by UIView animations setting the UIView's origin to some value based on where the touch ended. It's a bit of work, but it would likely be easier than trying to send touch events to two places when Apple wants to consume them in the ScrollView.

Upvotes: 0

Miraslau
Miraslau

Reputation: 548

Your button doesn't recognize clicks because the tapGestureRecognizer intercepts them. You can set more complicated area where tapGestureRecognizer has major priority. Try to add this code:

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    if (gestureRecognizer == yourTapGestureRecognizer) {
        return !CGRectContainsPoint(yourButton.frame, [gestureRecognizer locationInView:yourScrollView]);
    }
    return YES;
}

Upvotes: 1

Related Questions