how to get the tag of the UIImageView I'm tapping?

前端 未结 3 1375
傲寒
傲寒 2020-12-16 05:29

i have several UIImageView, each of them has a tag; and I have an array of Images, what i want to do is: when user tap one of the UIImageView, the app give back the certain

3条回答
  •  别那么骄傲
    2020-12-16 05:47

    To find out which image has to be touch ,use touchBegan method:

    Note: First of all you need to confirm about image view should be userIntrectionEnabled=YES; Now use this method:

    -(void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event{
        // get touch event
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint touchLocation = [touch locationInView:self.view];
        if ([touch view].tag == 800) {
    
         //if image tag mated then perform this action      
        }
    }
    

    You can use switch statement inside touchBegan.

提交回复
热议问题