#import "UIViewAnimationController.h"
@interface UIViewAnimationController (){
UIView *animationView;
}
@end
@implementation UIViewAnimationController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor orangeColor]; //設置背景色
//創建animationView
animationView =[[UIView alloc]initWithFrame:CGRectMake(100, 500, 100, 100)];
animationView.backgroundColor = [UIColor colorWithRed:0.5 green:0.8 blue:0.4 alpha:1.0];
UIImage *image = [UIImage imageNamed:@"心鈕釦.jpg"];
UIImageView *imageView = [[UIImageView alloc]initWithImage:image];
imageView.frame = animationView.bounds; // 將animation.brunds代替frame 防止視圖旋轉時找不到frame
[animationView addSubview:imageView];
[self.view addSubview:animationView5];
[animationView5 release];
//添加一個手勢 控制 圖片的大小
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(start)];
[self.view addGestureRecognizer:tap];
[tap release];
//tap觸發的方法
-(void)start{
NSLog(@"開始");
// [self propertyAnimation1];
//定時器代替上面的調用 實現觸發一次 就能一直執行
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(propertyAnimation1) userInfo:nil repeats:YES];
}
屬性動畫 方法
-(void)propertyAnimation1{
[UIView beginAnimations:@"圖片" context:NULL];
animationView5.transform = CGAffineTransformScale(animationView5.transform, 2, 2);//圖片擴大
animationView5.transform = CGAffineTransformScale(animationView5.transform, 0.5, 0.5);//圖片縮小
[UIView commitAnimations];
}
}
書寫步驟:1. 先創建UIView *animationView (設置 大小 背景色添加到視圖 釋放 );
2.設置一個手勢 以及觸發方法
3.屬性動畫方法 (動畫開始begin 和 動畫結束commit之間 設置屬性 如 動畫時長 旋轉角度 移動距離 )(兩種方法 一種點語法 animation.tranform 另一種是塊語法)
注意:圖片加到視圖上的位置(frame 或 bounds)