TransForm简单用法

  1 - (IBAction)btbAction1:(UIButton *)sender {
  2     
  3     
  4     __block ViewController *VC = self ;
  5     
  6     [UIView animateWithDuration:1 animations:^{
  7        
  8         
  9         //1.平移
 10         
 11         //在原来的基础上平移,再次点击按钮则不会移动
 12         
 13 //        CGAffineTransform make_translate = CGAffineTransformMakeTranslation(50, 0);
 14 //        
 15 //        
 16 //        VC.broderView.transform = make_translate ;
 17         
 18         //2.可以连续平移
 19         
 20         //参数1:在谁的基础上平移
 21 //        CGAffineTransform translate = CGAffineTransformTranslate(VC.broderView.transform, 10, 0);
 22 //        
 23 //        VC.broderView.transform = translate ;
 24         
 25         
 26         //3.旋转
 27         //旋转的度数
 28 //        CGAffineTransform make_rotate = CGAffineTransformMakeRotation(M_PI_4);
 29 //        
 30 //        VC.broderView.transform = make_rotate ;
 31 //
 32         
 33         //4.可连续旋转
 34         
 35         CGAffineTransform rotation = CGAffineTransformRotate(VC.broderView.transform, M_PI_4);
 36         
 37 //        VC.broderView.transform = rotation ;
 38         
 39         
 40         
 41         //5.只能一次收缩
 42         
 43 //        CGAffineTransform make_scale = CGAffineTransformMakeScale(0.5, 0.5);
 44 //        
 45 //        VC.broderView.transform = make_scale ;
 46         
 47         
 48         //连续收缩
 49         
 50         CGAffineTransform scale = CGAffineTransformScale(VC.broderView.transform, 0.8, 0.8);
 51         
 52 //        VC.broderView.transform = scale ;
 53         
 54         
 55         //合并两种仿射变换效果 (合并两种效果)
 56         CGAffineTransform contact = CGAffineTransformConcat(rotation, scale);
 57         
 58         VC.broderView.transform = contact ;
 59         
 60     }];
 61     
 62     
 63 }
 64 
 65 
 66 - (IBAction)btnAction2:(UIButton *)sender {
 67     
 68     
 69     //设置锚点,锚点位置不会变化,如果设置锚点,会调整view本身的位置去设置锚点的参数,所以不在点击方法里边设置
 70     self.myView.layer.anchorPoint = CGPointMake(0.5, 0.9);
 71     
 72     
 73     /*
 74      参数1:隔多久执行一次
 75      参数3:定时器的执行方法
 76      参数4:用户信息
 77      参数5:是否重复
 78      */
 79     
 80     [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
 81     
 82     
 83     
 84     
 85     
 86 }
 87 
 88 -(void)timerAction{
 89     
 90     
 91     self.myView.layer.transform = CATransform3DRotate(self.myView.layer.transform, M_PI / 30, 0, 0, 1);
 92     
 93     
 94 }
 95 
 96 
 97 - (void)dealloc {
 98     [_broderView release];
 99     [_myView release];
100     [super dealloc];
101 }
102 @end

 

posted @ 2015-10-14 21:31  YX祥  阅读(419)  评论(0编辑  收藏  举报