Search code examples
iosuiviewuitouch

How to send touch event to a UIView on iOS


I have added a tap gesture on a view. When the view tapped, an internal method called and an alert popped up.

Now I want to send touch event to simulate finger touch on this view. How could I do this?

===============

Thanks all.

I think I should describe question clearly. I'm work on ReplayKit on iOS12. We can add RPSystemBroadcastPickerView to our custom view. In my project, click a button, RPSystemBroadcastPickerView init and add in my view, tap on RPSystemBroadcastPickerView, select items, and click Start Broadcast.

What I want to do is that When I click button, it jump to the select items interface automatically. Just like sending touch event to RPSystemBroadcastPickerView after button clicked.


Solution

  • UIButton *btnInPicker = nil;
    for( UIView *_subView in self.broadcastPicker.subviews) {
        if( [_subView isKindOfClass:[UIButton class]] ) {
            btnInPicker = (UIButton *)_subView;
            break;
        }
    }
    
    
    if(btnInPicker) {
        [btnInPicker sendActionsForControlEvents:UIControlEventTouchDown];
    }
    

    but it has a issue: Unbalanced calls to begin/end appearance transitions for