zoukankan      html  css  js  c++  java
  • UIImageView动画

     设置动画方法一:简易版本的动画(使用block版本)

    //动画需要持续多久  第一个参数 动画持续的时间

        [UIView animateWithDuration:5 animations:^{

            //设置 改变x y坐标,大小(frame),也可以用transform,用形变来添加动画的效果

            view.transform = CGAffineTransformMakeRotation(M_PI);

            view.transform = CGAffineTransformRotate(view.transform,M_PI);

            

            view.transform = CGAffineTransformScale(view.transform, 0.5, 0.5);

            //view.transform = CGAffineTransformMakeScale(0.5, 0.5);只是执行了旋转,但是没有旋转的效果,依然只是执行了缩放,带make的方法不能叠加

        }];

    设置动画方法二:简易版本的动画(使用block版本)

    //第一个参数是动画持续的时间  第二个参数 是动画执行的代码块,第三个参数 动画结束的代码块

        [UIView animateWithDuration:5.0 animations:^{

            label.transform = CGAffineTransformTranslate(label.transform, 100, 0);

            label.transform = CGAffineTransformRotate(label.transform, M_PI);

        } completion:^(BOOL finished) {

            NSLog(@"动画结束了");

            [UIView animateWithDuration:2.0 animations:^{

                label.alpha = 0;//慢慢消失

                //[label removeFromSuperview];直接删除

            }];

        }];

    设置动画方法三:(复杂动画)

     //创建一个上下文(其实就是一个开始 跟结束范围)

        //开始设置动画相关属性

        [UIView beginAnimations:nil context:NULL];

        //持续时间

        [UIView setAnimationDuration:5.0];

        

        /*设置加速度变化曲线

         开始慢 结束慢 中间块

         UIViewAnimationCurveEaseInOut  慢快慢

         UIViewAnimationCurveEaseIn     慢=>快

         UIViewAnimationCurveEaseOut    快=>慢

         UIViewAnimationCurveLinear     线性

         */

        [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];

        //延迟时间  动画开始时延迟的时间

        [UIView setAnimationDelay:1];

        //设置自动恢复,一般是NO;

        [UIView setAnimatiounRepeatAtoreverses:NO];

        //动画重复次数,-1表示永远重复

        [UIView setAnimationRepeatCount:1];

        //设置动画的最终信息,一定放到最后

        view.transform = CGAffineTransformTranslate(view.transform, 100, 0);

        [UIView setAnimationDelegate:self];

        [UIView setAnimationDidStopSelector:@selector(finish)];

        //提交动画

        [UIView commitAnimations];

    UIImageView的常用属性和方法

    • contentMode属性:图片的填充模式。(继承自UIView)

    //充满整个视图

    //    UIViewContentModeScaleToFill

    //    UIViewContentModeRedraw

    //按照最大受限条件

    //    UIViewContentModeScaleAspectFit

    //按照最大标准缩放

    //    UIViewContentModeScaleAspectFill,

               

    //    UIViewContentModeCenter,          

    //    UIViewContentModeTop,

    //    UIViewContentModeBottom,

    //    UIViewContentModeLeft,

    //    UIViewContentModeRight,

    //    UIViewContentModeTopLeft,

    //    UIViewContentModeTopRight,

    //    UIViewContentModeBottomLeft,

    //    UIViewContentModeBottomRight,

        imgeView.contentMode = UIViewContentModeScaleToFill;

    • clipsToBounds属性:修剪超出边界的部分。(继承自UIView)

       //允许剪切边界

        imgeView.clipsToBounds = YES;

        //设置圆角,将边角剪切成圆角

        imgeView.layer.cornerRadius = 50;

    UIImageView动画属性

    • animationImages属性:装在用于动画的图像的数组。
    • animationDuration属性:动画播放的持续时间。
    • animationRepeatCount属性:动画的重复次数,0表示循环播放。
      • startAnimating方法:开始播放动画。
      • stopAnimating方法:停止播放动画。
      • isAnimating方法:返回BOOL值表示动画是否正在播放中。

    例子:鸟飞

    - (void)testImageViewAnimate {

        //创建一个数组,加入全部的图片对象

        NSMutableArray *birdArr = [NSMutableArray array];

        for (NSInteger i = 1; i <= 18; i++) {

            NSString *name = [NSString stringWithFormat:@"DOVE%02ld",i];

            UIImage *image = [UIImage imageNamed:name];

            [birdArr addObject:image];

        }

        //创建图片视图

        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(10, 300, 100, 100)];

        imageView.image = [UIImage imageNamed:@"DOVE01"];

        [self.view addSubview:imageView];

        

        //设置图片动画

        //设置图片动画的数组

        imageView.animationImages = birdArr;

        //设置动画的时间

        imageView.animationDuration = 1.0;

        [imageView startAnimating];

    }

  • 相关阅读:
    Python学习【第五篇】:面向对象及相关
    Python之路【第四篇】:模块
    Python之路【第三篇】:python基础(二)
    Python之路【第二篇】:Python基础(一)
    Python之路【第一篇】:Python简介和入门
    Open-source Tutorial
    Algorithms
    Mathematics Base
    Mathematics Base
    Open-source Tutorial
  • 原文地址:https://www.cnblogs.com/jiang-xiao-yan/p/5952551.html
Copyright © 2011-2022 走看看