transform 形变

  • 这个UIView的属性,书友继承UIView的控件都具有这个属性

  • 形变,X/Y方向

//相对于坐标的起始点做形变(最原始的位置)
 self.imageView.transform = CGAffineTransformMakeTranslation(0, 10);
 
 //相对于已经发生形变的地方 发生二次形变
 self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, 0, 10);
    


  • 缩放
//在原来的基础上 在进行一次缩放
//原始scale是1
self.imageView.transform = CGAffineTransformScale(self.imageView.transform, 1.5, 1.5);

  • 旋转
//在原来的基础上 进行旋转
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, 45);

  • 还原
  self.imageView.transform = CGAffineTransformIdentity;

iOS之动画(transform和UIView动画)

UIView渐变动画

简单动画

  • 简单动画
 [UIView animateWithDuration:2.0 animations:^{
        // 1.动画代码
        CGRect frame = self.animationView.frame;
        frame.origin.y -= 50;
        self.animationView.frame = frame;
    }];

  • 动画完成后 要执行什么操作
[UIView animateWithDuration:1.0 animations:^{
        // 执行动画
        CGRect frame = self.animationView.frame;
        frame.origin.y -= 50;
        self.animationView.frame = frame;
    } completion:^(BOOL finished) {
       // 动画完成做什么事情
        self.animationView.backgroundColor = [UIColor blackColor];
    }];

  • 动画伴随着速率的变化
   /*
     UIViewAnimationOptionCurveEaseInOut  动画开始/结束比较缓慢,中间相对较快
     UIViewAnimationOptionCurveEaseIn     动画开始比较缓慢
     UIViewAnimationOptionCurveEaseOut    动画结束比较缓慢
     UIViewAnimationOptionCurveLinear     线性---> 匀速
     */
     
     [UIView animateWithDuration:1.0 delay:1.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        //做动画
        CGRect frame = self.animationView.frame;
        frame.origin.y += 50;
        self.animationView.frame = frame;
        
    } completion:^(BOOL finished) {
    //动画完成 改变View的颜色
        self.animationView.backgroundColor = [UIColor greenColor];
    }];



  • 弹性动画
	/*
	Duration: 持续时间
	delay: 延迟时间 
	dampingRatio: 弹性系数 0-1之间取值
	velocity  :速率
	*/
	

   [UIView animateWithDuration:2.0 delay:0.5 usingSpringWithDamping:0.3 initialSpringVelocity:200 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        
        CGRect frame = self.animationView.frame;
        frame.origin.y += 50;
        self.animationView.frame = frame;
    } completion:^(BOOL finished) {
        
    }];

iOS之动画(transform和UIView动画)

相关文章: