iosobjective-cuiviewuitapgesturerecognizer

Programmatically invoking tap gesture for UIView


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

I would like to invoke the tap programmatically.

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 programmatically?


Solution

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

    [self handleSingleTap: oneTap];