2015-12-23 50 views
0

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

 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() 
     } 
     ) 
+0

什么不起作用? – Caleb

+0

从视图中删除标签消失后 – simon

+0

我看到'self.minusLabel.removeFromSuperview()'行。这正是它所做的。您可以使用'self.minusLabel.alpha = 1'来重置'alpha',以便您能够再次看到它。从视图中移除标签不会重置任何标签的属性。 – Caleb

回答

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