Tap gesture is not working in imageView but it working another view

泪湿孤枕 提交于 2019-12-02 13:26:57

问题


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....



来源:https://stackoverflow.com/questions/28542228/tap-gesture-is-not-working-in-imageview-but-it-working-another-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!