向下、向上和移动触摸之间的区别



因为我有点困惑不知道on_touch_down((之间的含义和区别, on_touch_move((, on_touch_up((。谁能解释一下这些功能是如何工作的?

注意:我已经阅读了文档,仍然无法理解。

为了正确解释,我将使用以下示例:

from kivy.app import App
from kivy.uix.widget import Widget
class MyWidget(Widget):
def on_touch_down(self, touch):
print("on_touch_down")
return super(MyWidget, self).on_touch_down(touch)
def on_touch_move(self, touch):
print("on_touch_move")
return super(MyWidget, self).on_touch_move(touch)
def on_touch_up(self, touch):
print("on_touch_up")
return super(MyWidget, self).on_touch_up(touch)
class MyApp(App):
def build(self):
return MyWidget()
if __name__ == '__main__':
MyApp().run()

如果我们用鼠标按下,然后移动它,然后释放它,我们会得到以下内容:

on_touch_down
on_touch_move
on_touch_move
on_touch_move
...
on_touch_move
on_touch_move
on_touch_move
on_touch_up

这正是这 3 个事件中管理的内容:

on_touch_down:第一次按下鼠标时调用。

on_touch_move:按住鼠标时移动鼠标时调用

on_touch_up:当您释放鼠标时调用它。

最新更新