消失之后删除标签

时间:2015-12-23 21:25:19

标签: xcode swift

我在这里有这个代码,我在那里展示标签,让它逐渐消失(这可以到达这里),然后我想删除它。一切正常,直到我想删除它。我需要删除它,以便我可以再次运行整个过程。 这是我的代码:

        view.addSubview(minusLabel)
        UIView.animateWithDuration(1.0, delay: 0.0, options: UIViewAnimationOptions.CurveEaseIn, animations: {
            self.minusLabel.alpha = 0
            }, completion: {
                (finished: Bool) -> Void in
                self.minusLabel.removeFromSuperview()
        }
        )

1 个答案:

答案 0 :(得分:0)

您不需要删除标签来重复动画,请尝试使用此代码,并根据您的喜好进行修改:

        func animate() {

            UIView.animateWithDuration(1.0, animations: {
            self.label.alpha = 1.0
            //label is the name of your label which you have defined/created

                }, completion: {
                    (Completed: Bool) -> Void in

                    UIView.animateWithDuration(1.0, delay: 0, options: UIViewAnimationOptions.CurveLinear, animations: {

                        self.label.alpha = 0
                        //label is the name of your label which you have defined/created

                        }, completion: {
                            (Completed: Bool) -> Void in

                            self.animate()
            })

            })

        }

每当您想要调用此函数时,请使用animate()及其下方添加label.alpha = 0(将标签更改为标签名称)。资料来源:https://www.youtube.com/watch?v=iyg3u3z_fKI