#import "RootViewController.h"
@interface RootViewController ()
@property (nonatomic, retain)UIImageView *imageView;
// 保存改变之前的位置,为了变换之后返回去
@property (nonatomic ,assign)CGPoint center;
// 保存初始化的frame
@property(nonatomic, assign)CGRect frame;
// 声明形变属性
@property (nonatomic, assign)CGAffineTransform transform;
@end
@implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self addSubViews];
}
- (void)addSubViews
{
self.imageView = [[UIImageView alloc] initWithFrame:(CGRectMake(80, 100, 200, 200))];
self.imageView.backgroundColor = [UIColor redColor];
self.imageView.image = [UIImage imageNamed:@"1.jpg"];
[self.view addSubview:self.imageView];
[self.imageView release];
// 保存中心点 为了
_center = self.imageView.center;
self.imageView.alpha = 1;
// 记录一下形变的属性
_transform = self.imageView.transform;
UIButton *button1 = [UIButton buttonWithType:(UIButtonTypeCustom)];
button1.frame = CGRectMake(200, 400, 40, 50);
button1.backgroundColor = [UIColor blueColor];
[button1 setTitle:@"点" forState:(UIControlStateNormal)];
[button1 addTarget:self action:@selector(actionBlockButton:) forControlEvents:(UIControlEventTouchUpInside)];
[self.view addSubview:button1];
}
// 点击方法
- (void)actionBlockButton:(UIButton *)button
{
// 缩放
[UIView animateWithDuration:1 animations:^{
// 设置反转
[UIView setAnimationRepeatAutoreverses:YES];
// 缩放
// 参数2,3,缩放比例
self.imageView.transform = CGAffineTransformScale(self.imageView.transform, 2,2);
} completion:^(BOOL finished) {
// self.imageView.transform = CGAffineTransformScale(self.imageView.transform, 1, 1);
// 复原
self.imageView.transform = _transform;
}];
}
#pragma mark-- 自己设置的代理方法
- (void)WillStart
{
NSLog(@"动画开始");
}
- (void)DidStop
{
NSLog(@"动画结束");
// 复原动画变化之前的位置
self.imageView.center = _center;
self.imageView.alpha = 1;
_frame = self.imageView.frame;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end