简单动画效果

//
//  AnimationViewController.m
//  AppUI组件学习
//
//  Created by 麦子 on 15/6/24.
//  Copyright (c) 2015年 麦子. All rights reserved.
//

#import "AnimationViewController.h"

@interface AnimationViewController (){
    UIView *view;

}

@end

@implementation AnimationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"动画学习";
    self.view.backgroundColor = [UIColor whiteColor];
    [self createView];
    
}


- (void)createView{
    view = [[UIView alloc] init];
    view.frame = CGRectMake(80, 80, 200, 100);
    view.backgroundColor = [UIColor redColor];
    [self.view addSubview:view];
    
    UIButton *btn = nil;
    for (int i = 0; i<3; i++) {
        btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        if (i == 0) {
            [btn setTitle:@"移动" forState:UIControlStateNormal];
            btn.frame = CGRectMake(120, 300, 100, 50);
        }else if (i == 1) {
            [btn setTitle:@"缩放" forState:UIControlStateNormal];
            btn.frame = CGRectMake(120, 380, 100, 50);
        }else if (i == 2) {
            [btn setTitle:@"旋转" forState:UIControlStateNormal];
            btn.frame = CGRectMake(120, 450, 100, 50);
        }
        btn.tag = i;
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
}


- (void)btnClick:(UIButton *)btn{
    
    switch (btn.tag) {
        case 0:{
            
            [UIView animateWithDuration:2 animations:^{
                // 在原来的位置上加 50,  就是改变Frame的值,达到的效果显示。
                view.transform = CGAffineTransformMakeTranslation(50, 50);
                
            } completion:^(BOOL finished) {
                
            }];            break;
        } case 1:{
            [UIView animateWithDuration:2 animations:^{
                
                view.transform = CGAffineTransformMakeScale(0.2, 0.2);
                
            } completion:^(BOOL finished) {
                
            }];
            
            
            break;
            
        } case 2:{
            
            [UIView animateWithDuration:2 animations:^{
                
                view.transform = CGAffineTransformMakeRotation(20*M_PI/180);
                
            } completion:^(BOOL finished) {
                
            }];
            
            
            break;
            
        }
        default:
            break;
    }
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}



@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值