在swift中删除动画 [英] Remove animation in swift

查看:442
本文介绍了在swift中删除动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a text field where user should enter info. And a label which points user to text field (like a hint).

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

I want to stop animation and remove hint label once user presses the text field to enter data.

正在文本标签上重复动画。创建者:

There is repeating animation on text label. Was created by:

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           
    )

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

After it I have created a function to remove annotation

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

应根据文档工作。

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

My label keeps flashing even though I see the string printed in console. I guess problem is that animation is repeated but have no clue how to resolve this issue.

推荐答案

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

 func remove()

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

}

更新:

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

If you want to go nuclear, you could do this, as well:

func nukeAllAnimations() {
    self.view.subviews.forEach({$0.layer.removeAllAnimations()})
    self.view.layer.removeAllAnimations()
    self.view.layoutIfNeeded()
}

这篇关于在swift中删除动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆