Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Photo Browser iPhone App UIKit Dynamics Extra Credit

Double tap gesture preceded by single tap

Hi,

Before starting the extra credit I'd like to fix a bug I have noticed in my app.

I add included the double tap to initiate the instagram Like in this method: '''

  • (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.imageView = [[UIImageView alloc] init];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(like)];
    tap.numberOfTapsRequired = 2;
    [self addGestureRecognizer:tap];
    
    [self.contentView addSubview:self.imageView];
    

    } return self; } '''

But when I double tab on the THPhotoViewController to like a picture, the single tap associated with opening the corresponding picture in THDetailViewController takes precedence.

What should I do to avoid this unwanted behavior?

I'd assume I'd need to reposition the double tab code somewhere else but would value expertise from the community. I am just a beginner.

Thanks, Arsene

4 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

If you look at the first link, when Amit answered he also provided a link to the project, where he changed it to using longPress gesture.

Thomas Nilsen
Thomas Nilsen
14,957 Points

I actually asked this exact same question a while back. Amit had a great answer -

https://teamtreehouse.com/forum/build-a-photo-browser-iphone-app-double-taps

Hi Thomas: Thanks for sharing. Good stuff.

Now, not sure I can locate the "long" code to debug. Would you have it by any chance?

Have a great day :)

Got it. He does the longPress instead of the double tap. I see. I was looking to change the single tap to transition to the DetailViewController into a longPress and keep the double tap to like.

Amit's answer seems better from a user experience standpoint.

Thank you!