首页 文章

Swift动画不起作用

提问于
浏览
0

一旦发生某些事情,我试图将UILabel和UIButton移动到我的应用程序的屏幕上,但是,当我使用动画执行此操作时,它不起作用,并且当动画应该发生时,组件不会移动到屏幕上 . 这是动画的代码:

UIView.animateWithDuration(2) { () -> Void in
                    self.label.center = CGPointMake(self.view.center.x, self.label.center.y)
                    self.again.center = CGPointMake(self.view.center.x, self.again.center.y)
                }

任何有关此问题的帮助将不胜感激!

2 回答

  • 0

    你应该试试这个 . 使用layoutIfNeeded()将重新定位所有内容 .

    UIView.animateWithDuration(2) { () -> Void in
    
                     self.label.center = CGPointMake(self.view.center.x, self.label.center.y)
                     self.again.center = CGPointMake(self.view.center.x, self.again.center.y)
                     self.view.layoutIfNeeded()
                }
    
  • 1

    试试这个!

    UIView.animateWithDuration(1.0,
    delay: 2.0,
    options: .CurveEaseInOut ,
    animations: {
    self.label.center = CGPointMake(self.view.center.x, self.label.center.y)
    self.again.center = CGPointMake(self.view.center.x, self.again.center.y)    },
    completion: { finished in
      println("Bug moved left!")
      self.faceBugRight()
    })
    }
    

相关问题