在kivy弹出窗口中,我看到可以通过声明来控制它是否可以制作动画
popup.open(animation=False)
或popup.dismiss(animation=False)
但是,当我不手动控制打开和关闭时,找不到找不到动画的方法。
以下是ModalView
中的一些代码,
这是Popup
def dismiss(self, *largs, **kwargs):
'''Close the view if it is open. If you really want to close the
view, whatever the on_dismiss event returns, you can use the *force*
argument:
::
view = ModalView()
view.dismiss(force=True)
When the view is dismissed, it will be faded out before being
removed from the parent. If you don't want animation, use::
view.dismiss(animation=False)
'''
if self._window is None:
return
if self.dispatch('on_dismiss') is True:
if kwargs.get('force', False) is not True:
return
if kwargs.get('animation', True):
Animation(_anim_alpha=0., d=self._anim_duration).start(self)
else:
self._anim_alpha = 0
self._real_remove_widget()
就像我提到的,我可以做popup.dismiss(animation=False)
来不运行动画。但是,当我自动关闭(触摸弹出窗口外部)时,找不到一种将参数放入其中的方法。
是否有一种方法可以不触碰ModalView
源本身?
总结:当我自动关闭弹出窗口时,我不做动画吗?
答案 0 :(得分:0)
我可以通过从dismiss()
继承ModalView
来解决此问题
class PopupNoAnimation(Popup):
def __init__(self, **kwargs):
super(PopupNoAnimation, self).__init__(**kwargs)
def dismiss(self, *largs, **kwargs):
if self._window is None:
return
if self.dispatch('on_dismiss') is True:
if kwargs.get('force', False) is not True:
return
self._anim_alpha = 0
self._real_remove_widget()
现在,dismiss
不会创建Animation
对象,这会导致关闭时没有动画。