//
// 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
简单动画效果
最新推荐文章于 2016-07-22 09:13:40 发布