1

我正在尝试实现某种行为,其中当点击进入对象的边界时对象执行一个方法,然后在点击离开其边界时执行另一个方法。由于这是一个难以用语言表达的场景,我画了一张图:

触摸拖动

这是哪种类型的 ControlEvent,如果它不存在,是否还有其他可接受的方法可以使其正常工作?

谢谢,詹姆斯

4

1 回答 1

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
    ...
}

希望这可以帮助

于 2013-08-06T21:44:35.730 回答