click on the texture area

人走茶凉 提交于 2020-01-06 07:00:37

问题


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.



来源:https://stackoverflow.com/questions/12162819/click-on-the-texture-area

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!