click on the texture area

2019-09-14 21:57发布

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条回答
家丑人穷心不美
2楼-- · 2019-09-14 22:09

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.

查看更多
登录 后发表回答