标签:
// 图片的移动和缩放
#import "ViewController.h"
@interface ViewController ()
- (IBAction)moveAndBig;
- (IBAction)move:(UIButton *)btn;
- (IBAction)zoom:(UIButton *)btn;
@property (nonatomic, weak) IBOutlet UIButton *head;
@end
@implementation ViewController
- (IBAction)moveAndBig
{
// 1.开启动画
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
// 2.修改属性
CGRect tempF = self.head.frame;
tempF.origin.x += 50;
tempF.origin.y += 100;
tempF.size.width += 50;
tempF.size.height += 50;
self.head.frame = tempF;
// 3.提交动画
[UIView commitAnimations];
}
#pragma mark 移动(上下左右)
- (IBAction)move:(UIButton *)btn
{
// 1.取出原来的属性
CGRect tempF = self.head.frame;
// 2.修改临时属性
CGFloat delta = 10;
switch (btn.tag) {
case 1: // 上
tempF.origin.y -= delta;
break;
case 2: // 下
tempF.origin.y += delta;
break;
case 3: // 左
tempF.origin.x -= delta;
break;
case 4: // 右
tempF.origin.x += delta;
break;
}
// 3.重新赋值
self.head.frame = tempF;
}
- (IBAction)zoom:(UIButton *)btn{
CGRect *tempFrame = self.head.frame;
CGFloat delta = 20;
switch (btn.tag){
case 5: // 放大
tempFrame.size.width += delta;
tempFrame.size.height += delta;
break;
case 6: // 缩小
tempFrame.size.width -= delta;
tempFrame.size.height -= delta;
break;
}
self.head.frame = tempFrame;
}
@end
--------------------------------------------------------
// 图片的移动和缩放(bounds和center)
#import "viewController.h"
@interface viewController ()
@property (nonatomic, weak) IBOutlet UIButton *head;
- (IBAction)move:(UIButton *)btn;
- (IBAction)zoom:(UIButton *)btn;
@end
@implementation viewController
#pragma mark 移动
- (IBAction)move:(UIButton *)btn{
CGPoint tempCenter = self.head.center;
CGFloat delta = 20;
switch (btn.tag){
case 1: // 上
tempCenter.y -= delta;
break;
case 2: // 下
tempCenter.y += delta;
break;
case 3: // 左
tempCenter.x -= delta;
break;
case 4: // 右
tempCenter.x += delta;
break;
}
self.head.center = tempCenter;
}
#pragma mark 缩放
- (IBAction)zoom:(UIButton *)btn{
CGRect tempBounds = self.head.bounds;
CGFloat delta = 20;
switch (btn.tag){
case 5: // 放大
tempBounds.size.width += delta;
tempBounds.size.height += delta;
break;
case 6: // 缩小
tempBounds.size.width -= delta;
tempBounds.size.height -= delta;
break;
}
self.head.bounds = tempBounds;
}
@end
标签:
原文地址:http://www.cnblogs.com/lianfu/p/4813900.html