Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method touchesBegan: is only called on a "long press" #15

Closed
lochetti opened this issue Sep 25, 2013 · 5 comments
Closed

Method touchesBegan: is only called on a "long press" #15

lochetti opened this issue Sep 25, 2013 · 5 comments

Comments

@lochetti
Copy link

I`m testing in a Iphone 4.

If I just tap the area of the segment, the method touchesBegan is not called. I have to do a top of a certain duration to get the method called.

@lochetti
Copy link
Author

The ideia is to use UITapGestureRecognizer.

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)];
[self addGestureRecognizer:tapGestureRecognizer];

and make the handleTapFrom

- (void) handleTapFrom: (UITapGestureRecognizer *)recognizer{
    //Code to handle the gesture
    CGPoint touchLocation = [recognizer locationInView:self];
    if (CGRectContainsPoint(self.bounds, touchLocation)) {
        NSInteger segment = touchLocation.x / self.segmentWidth;
        if (segment != self.selectedSegmentIndex) {
            [self setSelectedSegmentIndex:segment animated:YES notify:NO];
        }
    }
}

@HeshamMegid
Copy link
Owner

Never came across that issue before but it's interesting. Which iOS version is that?

@lochetti
Copy link
Author

Tested on a iOS 6.1.3

@HeshamMegid
Copy link
Owner

I've been unable to reproduce this on my side so I'll close it for now.

@btrzupek
Copy link

I had a similar situation and just determine the issue. I have a tapGestureRecognizer on the main view for the ViewController (for keyboard dismisses for another function). That one was eating the events for the segment control.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants