Tap gesture is not working in imageView but it wor

2020-04-21 07:58发布

问题:

i have working in image and video overlay in that i put one image view, i assigned the tapGestureRecognizer to that image view its not working,For video i put one MPMoviePlayerController and i set the tapGestureRecognizer to it this one working fine but the image view only not working.Below is my code

- (void)viewDidLoad {
    [super viewDidLoad];
    videoimg=[[UIImageView alloc]init];//OvelayImage
    videoimg.image=[UIImage imageNamed:@"fb.png"];
    videoimg.userInteractionEnabled=YES;
    videoimg.multipleTouchEnabled=YES;
    [self.imgView bringSubviewToFront:videoimg];

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imagePan:)];

    tap.numberOfTapsRequired=1;
    tap.numberOfTouchesRequired=1;

    [videoimg addGestureRecognizer:tap];
    [self.imgView addSubview:videoimg];//add the overlay image to Main imageView 
    [self.videoPlayerView.view addSubview:videoimg];//MPMoviePlayerController-add the overlay image to VideoView
}

//Gesture
-(void)imagePan:(UITapGestureRecognizer*)ges{

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Image" message:@"FB Image Clicked..."
                                                   delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}

回答1:

videoimg=[[UIImageView alloc]init];
videoimg.image=[UIImage imageNamed:@"fb.png"];
videoimg.userInteractionEnabled=YES;

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imagePan:)];
[videoimg setGestureRecognizers:[NSArray arrayWithObject:tap]];
tap.numberOfTapsRequired=1;
[self.videoPlayerView.view addSubview:videoimg];

use it may help you....