ios激情详解之动画缩放

13 篇文章 0 订阅
#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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值