GETTING TAP GESTURE ON UICOLLECTIONVIEWCELL IN IOS.

Felix Pickles

Total Post:24

Points:168
Posted by  Felix Pickles
 762  View(s)
Ratings:
Rate this:

I am created a collection view cell to display multiple images. My problem is how to get tap gesture on a small icon, which is on top right cell image.

I am using this code:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(projectSetting:)];
iconButton = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageName.png"]];
iconButton.frame = CGRectMake(50, 10, 50, 50);
[iconButton addGestureRecognizer:tapped];
[cell addSubview:iconButton];

Please anyone tell me what's wrong in my code?

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Getting tap gesture on UICollectionViewCell in iOS.

    To identify the tap on the icon, add tap Gesture Recogniser on the icon:

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];

    [icon addGestureRecognizer:singleTap];

    after that add handleSingleTap: method-

    -(void)handleSingleTap:(id)sender
    {
        // do your stuff;
    }

      Modified On Dec-25-2015 10:24:35 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!