• UIView的动画


    //

    //  ViewController.m

    //  UI-NO.6

    //

    //  Created by Bruce on 15/7/20.

    //  Copyright (c) 2015年 Bruce. All rights reserved.

    //

    #import "ViewController.h"

    @interface ViewController ()

    {

        UIImageView *animationView;

        NSMutableArray *imageList;

    }

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        self.view.backgroundColor = [UIColor orangeColor];

        

        [self loadData];

        

        UIImage *image = [UIImage imageNamed:@"niao2-1(被拖移).tiff"];

        

        animationView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, image.size.width, image.size.height)];

    //    设置UIImageView播放的动态图数组

        animationView.animationImages = imageList;

    //    播放一组动画 需要的时间

        animationView.animationDuration = 1;

        animationView.animationRepeatCount = -1;

        [self.view addSubview:animationView];

    //    让动画开始

    //    [animationView startAnimating];

    //    让动画结束

    //    [animationView stopAnimating];

    //    判断动画是否正在播放

    //    animationView.isAnimating

        

        

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

        button.frame = CGRectMake(10, 20, 50, 35);

        [button setTitle:@"播放" forState:UIControlStateNormal];

        [button setTitle:@"暂停" forState:UIControlStateSelected];

        [button setTitleColor:[UIColor brownColor] forState:UIControlStateNormal];

        [button addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:button];

    }

    - (void)play:(UIButton *)sender

    {

        

        if (sender.selected != YES) {

    //        播放动画  重置按钮的title

            

            sender.selected = YES;

            [animationView startAnimating];

            [self moveAnimation];

            

        }else{

            

            sender.selected = NO;

            [animationView stopAnimating];

        }

        

    }

    - (void)loadData

    {

    //    当调试的时候  打印数组的值 是nil或者null 意味着 咱们没有初始化数组对象  或者 有被赋值为nil或者null(数组对象就会被销毁) 的情况

        

        imageList = [NSMutableArray array];

        

        for (int i=1; i<=6; i++) {

            

            NSString *imageName = [NSString stringWithFormat:@"niao2-%d(被拖移).tiff",i];

            [imageList addObject:[UIImage imageNamed:imageName]];

            

        }

        

    }

    - (void)moveAnimation

    {

        UIImage *image = [UIImage imageNamed:@"niao2-1(被拖移).tiff"];

    //    Duration 动画持续的时间

    //    [UIView animateWithDuration:5 animations:^{

    //        animationView.frame = CGRectMake(200, 400, image.size.width*2, image.size.height*2);

    //    }];

        

        

        [UIView animateWithDuration:5 animations:^{

            animationView.frame = CGRectMake(200, 400, image.size.width*2, image.size.height*2);

        } completion:^(BOOL finished) {

            [UIView animateWithDuration:5 animations:^{

                animationView.frame = CGRectMake(0, 0, image.size.width, image.size.height);

            }];

        }];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    ThinkPHP之APP_DEBUG给我带来的问题
    yii框架部署
    论文翻译之--- 软件设计师怎样使用标记来帮助提醒和重新查找
    初始html5,遇到的第一个问题
    几种进入mysql的方法
    百度经验---一些生活常见问题的解决
    myeclipse背景色设置遇到的问题
    linux学习(二)-----Linux 的目录结构、远程登录、vi和vim
    linux学习(一)-----vm、centos安装
    springboot核心技术(四)-----Docker、数据访问、自定义starter
  • 原文地址:https://www.cnblogs.com/wukun16/p/4883959.html
Copyright © 2020-2023  润新知