头尾式动画


#import "ViewController.h"


@interface ViewController ()


//放大

- (IBAction)big ;

//缩小

- (IBAction)samll ;


//头像

@property(nonatomic,weak)IBOutlet UIButton *head;


//移动

- (IBAction)move:(UIButton *)btn;

@end


@implementation ViewController


- (void)big{

//     NSLog(@"我看到一个big美女");

    //    1.取出对象的结构体属性frame,赋值给临时变量

    CGRect tempFrame = self.head.frame;

1.取出对象的结构体属性bounds,赋值给临时变量

    CGRect tempBounds = self.head.bounds;



    //    2.修改临时变量的值

    //    tempFrame.origin.y = tempFrame.origin.y - 10;

    

 tempBounds.size.width += 10;

    tempBounds.size.height += 10;

    tempFrame.size.width += 10;

    tempFrame.size.height += 10;

    //    3.用临时变量的值覆盖原来的变量

    self.head.frame = tempFrame;

    NSLog(@"%@",NSStringFromCGRect(self.head.frame));


    

    

}


- (void)samll{

//     NSLog(@"我看到一个samll美女");

    //    1.取出对象的结构体属性frame,赋值给临时变量

    CGRect tempFrame = self.head.frame;

    //    2.修改临时变量的值

    //    tempFrame.origin.y = tempFrame.origin.y - 10;

    

    tempFrame.size.width -= 10;

    tempFrame.size.height -= 10;

    //    3.用临时变量的值覆盖原来的变量

    self.head.frame = tempFrame;


    

    

}


//如果用一个方法监听按钮点击,如果传入一个参数,那么会把对应的点击的按钮当成参数传递进来


- (void)move:(UIButton *)btn{

    

//    NSLog(@"%@",NSStringFromCGRect(btn.frame));

    

// 头尾式动画

    

    NSLog(@"%@",btn);

    

     //   0.开启动画

    [UIView beginAnimations:nil context:nil];

    //    0.1设置动画时间

    [UIView setAnimationDuration:1.0];

    

    //    1.取出对象的结构体属性frame,赋值给临时变量

    CGRect tempFrame = self.head.frame;

    

 //    1.取出对象的结构体属性frame,赋值给临时变量

    CGPoint tempCenter = self.head.center;

    


    CGFloat dealta = 50;

    

    switch (btn.tag) {

        case 10:

//------------------------$------------------------------------

             tempCenter.y -= dealta


            tempFrame.origin.y -= dealta;

            break;

        case 20:

            tempFrame.origin.y += dealta;

            break;


        case 30:

            tempFrame.origin.x -= dealta;

            break;


        case 40:

            tempFrame.origin.x += dealta;

            break;


            

          

    

    

    }

    

    //    3.用临时变量的值覆盖原来的变量

    self.head.frame = tempFrame;

    //    4.提交动画

    [UIView commitAnimations];


    

    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值