#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];
}