tap gesture not recognized on uiimageview

前端 未结 2 883
星月不相逢
星月不相逢 2020-12-08 19:47

I added two uiimageviews, one on another subview uiview (imageview1,imageview2). In the first view the top uiimageview is

相关标签:
2条回答
  • 2020-12-08 20:02

    Try setting setUserInteractionEnabled:YES before adding gesture recognizer.

    [imageview1 setUserInteractionEnabled:YES]
    [imageview2 setUserInteractionEnabled:YES]
    
    [imageview1 addGestureRecognizer:singleTap];
    [imageview2 addGestureRecognizer:singleTap1];   
    

    Update:

    After the comment you have made I suggest you bring your views to the top before detecting the tap event. Because parent imageView is above and catches these taps.

    [yourparentview bringSubviewToFront:imageview1];
    [yourparentview bringSubviewToFront:imageview2];
    
    0 讨论(0)
  • 2020-12-08 20:11
    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(oneTap:)];
    singleTap.numberOfTapsRequired = 1;
    singleTap.numberOfTouchesRequired = 1;
    singleTap.delegate = self;
    [imageview1 addGestureRecogniser:singleTap];
    [singleTap1 release];
    
    imageview1.userInteractionEnabled = YES; //disabled by default
    
    0 讨论(0)
提交回复
热议问题