快速删除动画

2023-12-29

我有一个文本字段,用户应在其中输入信息。还有一个将用户指向文本字段的标签(如提示)。

一旦用户按下文本字段输入数据,我想停止动画并删除提示标签。

文本标签上有重复的动画。创建者:

override func viewDidLoad() {
    super.viewDidLoad()

    textInput.addTarget(self, action: #selector(CalculatorViewController.removeAnimation(_:)), forControlEvents: UIControlEvents.TouchDown)

     self.hintLabel.alpha = 0.0

    UIView.animateWithDuration(1.5, delay: 0, options: .Repeat
        , animations: ({
        self.hintLabel.alpha = 1.0
    }), completion: nil           
    )

之后我创建了一个函数来删除注释

func removeAnimation(textField: UITextField) {
    view.layer.removeAllAnimations()
    self.view.layer.removeAllAnimations()
    print("is it working?!")
}

应根据文档进行工作。

即使我看到控制台中打印的字符串,我的标签仍然闪烁。我猜问题是动画重复了,但不知道如何解决这个问题。


//Just remove the animation from the label. It will Work

 func remove()

{
    self.hintLabel.layer.removeAllAnimations()
    self.view.layer.removeAllAnimations()
    self.view.layoutIfNeeded()

}

Update:

如果你想使用核技术,你也可以这样做:

func nukeAllAnimations() {
    self.view.subviews.forEach({$0.layer.removeAllAnimations()})
    self.view.layer.removeAllAnimations()
    self.view.layoutIfNeeded()
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

快速删除动画 的相关文章

随机推荐