复习:
1.加载图片
2.2个按钮,1个放大图片,1个缩小图片
3.动画:慢-快,动画结束后,打印“动画已经结束”
复习:
6月8日
源码
//
// ViewController.m
// 057
//
// Created by Encore on 16/6/8.
// Copyright © 2016年 trauson. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
_imageView=[[UIImageView alloc] init];
_imageView.frame=CGRectMake(100, 100, 80, 80);
_imageView.image=[UIImage imageNamed:@"link.jpg"];
_imageView.tag=101;
[self.view addSubview:_imageView];
UIButton *btnMove=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnMove setTitle:@"移动" forState:UIControlStateNormal];
btnMove.frame=CGRectMake(100, 350, 80, 40);
[btnMove addTarget:self action:@selector(pressMove) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnMove];
UIButton *btnScale=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnScale setTitle:@"缩放" forState:UIControlStateNormal];
btnScale.frame=CGRectMake(100, 450, 80, 40);
[btnScale addTarget:self action:@selector(pressScale) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnScale];
}
-(void)pressMove
{
//开始动画函数,准备动画的开始工作
[UIView beginAnimations:nil context:nil];
//设置动画时间函数,参数时间长度,以秒为单位
[UIView setAnimationDuration:10];
//设置动画开始的延时时间长度
//进行延时动画的处理
//参数的单位:秒
[UIView setAnimationDelay:0];
//设置动画的代理对象
[UIView setAnimationDelegate:self];
//设置动画结束调用的函数
[UIView setAnimationDidStopSelector:@selector(stopAnim)];
//设置动画运动的轨迹的方式
//Linar线性运动
//EaseIn 慢慢加快
//EaseOut 慢慢减速
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
//目标位置
_imageView.frame=CGRectMake(100, 300, 80, 80);
//提交运行动画
[UIView commitAnimations];
}
-(void)stopAnim
{
NSLog(@"动画结束!");
}
-(void)pressScale
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:1];
//
[UIView setAnimationDidStopSelector:@selector(stopAnim)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut]
_imageView.frame=CGRectMake(100, 300, 10, 10);;
[UIView commitAnimations];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end