CAAnimation
在ViewController.m中
- (void)viewDidLoad {
    [super viewDidLoad];
    
  
       self.imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tutu.png"]];
    self.imageView.frame = CGRectMake(100, 100, 100, 100);
    [self.view addSubview:self.imageView];
//添加一个计时器,scheduledTimerWithTimeInterval参数代表 多长时间执行一次,
    [NSTimer  scheduledTimerWithTimeInterval:1 target:self selector:@selector(zhuanzhuan) userInfo:nil repeats:YES];
}
-(void)zhuanzhuan{
    
   [UIView  animateWithDuration:1.0f animations:^{
__weak typeof(self)pSelf = self;
   //根据nstimer的设置,到这里一秒执行一次旋转,
       //让一个view 按照它的本身的transform 去改变 transform  可以多次执行
         //第一个参数    获取一个view transform
       //第二个参数  旋转的角度
       self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, M_PI/2);
//,同样的缩放也是一秒一次
     if (self.imageView.frame.size.width>200) {
           pSelf.imageView.transform = CGAffineTransformScale(pSelf.imageView.transform, 0.5, 0.5);
           NSLog(@"2");
      }else{
       
           pSelf.imageView1.transform = CGAffineTransformScale(pSelf.imageView.transform, 2, 2);
       
           NSLog(@"1");
       }
       //从屏幕的四周走一遍
       if (pSelf.imageView.frame.origin.x == 0 && pSelf.imageView.frame.origin.y == 0) {
          pSelf.imageView.transform = CGAffineTransformTranslate(pSelf.imageView.transform, pSelf.view.frame.size.width - 200, 0);
       } else if (pSelf.imageView.frame.origin.x == pSelf.view.frame.size.width - 200 && pSelf.imageView.frame.origin.y == 0) {
           pSelf.imageView.transform = CGAffineTransformTranslate(pSelf.imageView.transform, 0, pSelf.view.frame.size.height - 200);
       } else if (pSelf.imageView.frame.origin.x == pSelf.view.frame.size.width - 200 && pSelf.imageView.frame.origin.y == pSelf.view.frame.size.height - 200) {
          pSelf.imageView.transform = CGAffineTransformTranslate(pSelf.imageView.transform, -(pSelf.view.frame.size.width - 200), 0);
      } else {
           pSelf.imageView.transform = CGAffineTransformTranslate(pSelf.imageView.transform, 0, -(pSelf.view.frame.size.height - 200));
       }
      
   }
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
     [UIView animateWithDuration:1.0f animations:^{
         //设置View的属性为旋转, 就一个参数代表旋转的角度 ,仅仅只是旋转一下,
     //  self.imageView.transform = CGAffineTransformMakeRotation(M_PI /4);
          //设置View的属性为缩放, 分别代表的是X方向 y方向放大的范围 ,缩放一下
        // self.imageView1.transform = CGAffineTransformMakeScale(2, 2);
         //设置View的transform为平移 两个参数 分别代表X方向 y方向, 平移的范围+ 和一切代表方向 平移一下
         self.imageView1.transform = CGAffineTransformMakeTranslation(100, 100);
         
         
        
         
     }];
    
}
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号