iOS学习应用开发就业课:第7章_056:UIView动画基础

复习:

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值