Search code examples
iosobjective-cuiviewuitapgesturerecognizer

Programatically invoking tap gesture for UIView


I've created a UIView programatically. I've added tap gesture action programatically.

I would like to invoke the tap programatically.

Here's what I've got so far.

MyUIView *myView = [[MyUIView alloc] init];

UITapGestureRecognizer *oneTap = 
  [[UITapGestureRecognizer alloc] initWithTarget:self 
                                          action:@selector(handleSingleTap:)];

[myView.addGestureRecognizer:oneTap];

Now I would like to invoke a tap event on this myView.

How can I do that programatically?


Solution

  • You have to just call handleSingleTap method just like you can call other methods,

    [self handleSingleTap: oneTap];