问题描述:

How do i pass an event from a subview to trigger UIControlEventTouchUpInside of its superview(a subclass of UIControl)? The subview has a triangular area of a certain size. If I remove my finger from within the triangle I want the UIControl superview to trigger its action. I tried to forward touchesEnd from the subview to the superview with nextResponder but it didn't work.

网友答案:

To programmatically fire an event on a UIControl, use this method:

- (void)sendActionsForControlEvents:(UIControlEvents)controlEvents

for example:

- (void)touchUpInside {
    // will need to cast superview to UIControl
    [[self superview] sendActionsForControlEvents:UIControlEventTouchUpInside];
}

more info on this method in the docs.

相关阅读:
Top