click on the texture area

2019-09-14 22:01发布

问题:

I'd like to create a function that will be called by clicking on texture object. I've just figured out how the button action is processed. Could you tell me plz how it works. Maybe some special controls have to be correspond to texture object? thanks in advance )))

回答1:

I assume this is for iOS and by click you mean tap. The following code will add a gesture recognizer to any UIView:

    myView.userInteractionEnabled = YES;
    UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    recognizer.numberOfTapsRequired = 1;
    recognizer.numberOfTouchesRequired = 1;

    [myView addGestureRecognizer:recognizer];

And implement your handler like this:

- (void)handleTap:(UITapGestureRecognizer *)sender {     
    if (sender.state == UIGestureRecognizerStateEnded) {
        //your code
    }
}

The handleTap: method will be called every time your view receives a tap.