在swift中删除动画

Alm*_*ini 10 animation uiviewanimation ios swift swift2

我有一个文本字段,用户应该输入信息.以及将用户指向文本字段的标签(如提示).

我想在用户按下文本字段输入数据后停止动画并删除提示标签.

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

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           
    )
Run Code Online (Sandbox Code Playgroud)

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

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

应该根据文件工作.

在此输入图像描述

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

小智 31

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

 func remove()

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

}
Run Code Online (Sandbox Code Playgroud)

更新:

如果你想要核,你也可以这样做:

func nukeAllAnimations() {
    self.view.subviews.forEach({$0.layer.removeAllAnimations()})
    self.view.layer.removeAllAnimations()
    self.view.layoutIfNeeded()
}
Run Code Online (Sandbox Code Playgroud)