iOS View Animations and Layer An

2015-11-23  本文已影响0人  Kevin_Shuai
一. View Animations 一些属性介绍
  UIView.animateWithDuration(0.5, delay: 0.3, options: [], animations: {
      //code 
      username.center.x += self.view.bounds.width                             
}, completion:nil)  在//code 加你想要怎么移动  上面例子可以使username.center.x 向右移动
二. Layer Animations

layer animations 比 View Animations 有更多的动画属性 更加灵活的控制动画

     let flyRight = CABasicAnimation(keyPath: "position.x")
     flyRight.fromValue = -view.bounds.size.width/2
     flyRight.toValue = view.bounds.size.width/2
     flyRight.duration = 0.5                                                          
     backgroundColor.autoreverses = true
     backgroundColor.repeatCount = 10
     username.addAnimation(flyRight, forKey:nil) 

这是简单的Layer Animations 和 UIView Animations 对比 实现的效果和上面的UIViewAnimation 一样 但是Layer Animation 的属性更多 并且可以被复用 下面介绍layer animation 常用属性

上一篇 下一篇

猜你喜欢

热点阅读