UIResponder和多UIControlEvents(UIResponder and multi

2019-09-21 14:19发布

有没有办法来调用多个UIControlEvents选择?

这并不工作,但itl'll作罢什么,我试图做一个想法。

[self.slider addTarget:self action:@selector(sliderDidStopDragging:) forControlEvents:UIControlEventTouchUpInside, UIControlEventTouchUpOutside];

谢谢!!

Answer 1:

尝试这种方式来代替:

// same selector for different events
[self.button addTarget:self action:@selector(selector0:) forControlEvents:UIControlEventTouchUpInside];
[self.button addTarget:self action:@selector(selector0:) forControlEvents:UIControlEventTouchUpOutside];
// etc...

或者你可以使用这个:

// different selectors for same event
[self.button addTarget:self action:@selector(selector1:) forControlEvents:UIControlEventTouchUpInside];
[self.button addTarget:self action:@selector(selector2:) forControlEvents:UIControlEventTouchUpInside];
// etc...


Answer 2:

只要OR它们:

[self.button addTarget:self action:@selector(selector0:) forControlEvents:(UIControlEventTouchUpInside|UIControlEventTouchUpOutside)];


文章来源: UIResponder and multiple UIControlEvents