点击手势在imageView中不起作用,但它在另一个视图中工作

时间:2015-02-16 13:13:22

标签: ios objective-c uiimageview uitapgesturerecognizer

我已经在图像和视频叠加工作,我放了一个图像视图,我将tapGestureRecognizer分配给该图像视图它不工作,对于视频我放了一个MPMoviePlayerController我设置tapGestureRecognizer给它这个工作正常但是图像视图只能不工作。下面是我的代码

- (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 个答案:

答案 0 :(得分:2)

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];

使用它可能对你有所帮助....