我正在尝试实现某种行为,当一个龙头进入对象的边界时,一个对象执行一个方法,然后当一个龙头离开它的边界时,另一个行为。由于这是一个难以理解的场景,我画了一张图片:
这是哪种类型的ControlEvent,如果它不存在,还有其他可接受的方法来实现这个吗?
谢谢, 詹姆斯
答案 0 :(得分:1)
我知道没有任何控制事件。你必须自己实现这一点。在视图控制器(超级视图到您的按钮)上放置以下方法,如下所示:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// Touches began, check the position of my touch. Is it outside a button?
// note that in a BOOL
...
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// was my first touch on a button? if not, see if my current touch is inside
// the button, note that
...
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
// Touch is ending, is my touch outside the button and did i cross through earlier?
// If so, "drag through" event is successful
...
}
希望这会有所帮助