首页 > 代码库 > (5.17)简单动画

(5.17)简单动画

- (IBAction)button:(UIButton *)sender {
    
    
     if (sender.tag == 0) {
         
    //计算view的frame属性
        NSString *frame = NSStringFromCGRect(_view1.frame);
        NSString *outframe = [NSString stringWithFormat:@"frame:%@",frame];
        [_message setText:outframe];

    }else if(sender.tag == 1){
      //计算view的bounds属性
        NSString *bounds = NSStringFromCGRect(_view1.bounds);
        NSString *outbounds = [NSString stringWithFormat:@"bounds:%@",bounds];
        [_message setText:outbounds];
        
    }else if(sender.tag == 2){
        //计算view的center属性
        NSString *center = NSStringFromCGPoint(_view1.center);
        NSString *outcenter = [NSString stringWithFormat:@"center:%@",center];
        [_message setText:outcenter];
        
    }else if (sender.tag == 3){
       //图像角度转向
        CGAffineTransform tranR =CGAffineTransformRotate(_view1.transform, M_PI_4);
 //早期的动画实现
//        //设定动画效果
//        [UIView beginAnimations:nil context:nil];
//        //设定动画时间长度
//        [UIView setAnimationDuration:1.0];
//        
//        [_view1 setTransform:tranR];
//        //  提交动画效果
//        [UIView commitAnimations];
//
        
    //block动画方法
        [UIView animateWithDuration:(1.0f) animations:^{
             [_view1 setTransform:tranR];
        }];

        
    }else if(sender.tag == 4){
        //图像放大
        CGAffineTransform tranS = CGAffineTransformScale(_view1.transform, 1.2, 1.2);
       //block动画方法
        [UIView animateWithDuration:(1.0f) animations:^{
            [_view1 setTransform:tranS];
        }];
        

    
    }else if(sender.tag == 5){
        //图像缩小
        CGAffineTransform tranR = CGAffineTransformScale(_view1.transform, 1/1.2, 1/1.2);
        //block动画方法
        [UIView animateWithDuration:(1.0f) animations:^{
              [_view1 setTransform:tranR];
        }];

        
    }else if (sender.tag == 6){
       //图像平移
        CGAffineTransform tranM = CGAffineTransformTranslate(_view1.transform , 0, 20);
        
     //block动画方法的嵌套
        [UIView animateWithDuration:1.0f animations:^{
             [_view1 setTransform:tranM];
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:1.0f animations:^{
                [_view1 setBackgroundColor:[UIColor redColor]];
                [_view1 setAlpha:0.1f];
            }];
        }];
        
        
    }
    
 
 
    
    
    
}
@end