transform:形变属性

  • 平移(Translation)

      CGAffineTransform CGAffineTransformMakeTranslation(CGFloat tx, CGFloat ty);
    
      self.tempView.transform = CGAffineTransformMakeTranslation(-100, 100);
    
  • 缩放(Scale),值范围:0-1

      CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy);
    
      self.tempView.transform = CGAffineTransformMakeScale(0.5, 0.5);
    
  • 旋转(Rotation)

      CGAffineTransform CGAffineTransformMakeRotation(CGFloat angle);
    
      self.tempView.transform = CGAffineTransformMakeRotation(-M_PI_4);
    
  • 效果重叠

      // 在原有形变基础上叠加 平移
      CGAffineTransform CGAffineTransformTranslate(CGAffineTransform t,
        CGFloat tx, CGFloat ty);
    
      // 在原有形变基础上叠加 缩放
      CGAffineTransform CGAffineTransformScale(CGAffineTransform t,
        CGFloat sx, CGFloat sy);
    
      // 在原有形变基础上叠加 旋转
      CGAffineTransform CGAffineTransformRotate(CGAffineTransform t,
        CGFloat angle);
    
      // 先平移
      CGAffineTransform translation = CGAffineTransformMakeTranslation(-100, 100);
    
      // 再缩放
      CGAffineTransform scaleTranslation = CGAffineTransformScale(translation, 0.5, 0.5);
    
      // 最后旋转
      CGAffineTransform rotateScaleTranslation = CGAffineTransformRotate(scaleTranslation, M_PI_2);
    
      self.tempView.transform = rotateScaleTranslation;
    
  • CGAffineTransformIdentity用于清空transform(变换),以前的平移、缩放、旋转都会消失
      [UIView animateWithDuration:2.0 animations:^{
          self.tempView.transform = CGAffineTransformIdentity;
      }];
    

results matching ""

    No results matching ""