iOS动画学习之缩放控件

实现控件的缩放很简单,就是用动画改变frame的大小。

  func animateLabel() { 
    // 1 
    holderView.removeFromSuperview() 
    view.backgroundColor = Colors.blue  
  // 2  
  var label: UILabel = UILabel(frame: view.frame) 
  label.textColor = Colors.white 
  label.font = UIFont(name: "HelveticaNeue-Thin", size: 170.0)  
  label.textAlignment = NSTextAlignment.Center 
  label.text = "S" label.transform =     CGAffineTransformScale(label.transform, 0.25, 0.25) 
  view.addSubview(label)  
  // 3  
  UIView.animateWithDuration(0.4, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.1, options: UIViewAnimationOptions.CurveEaseInOut, 
  animations: ({ 
    label.transform = CGAffineTransformScale(label.transform, 4.0, 4.0) }), completion: nil)}

和操作layer的动画不同,控件缩放其实是调用UIView的静态方法。设置缩放比例即可。

你可能感兴趣的:(iOS动画学习之缩放控件)