UIView动画
一、commitAnimations方式使用UIView动画
1、commitAnimations方式使用UIView动画
[UIView beginAnimations:@"animation" context:nil]; //UIView开始动画,第一个参数是动画的标识,第二个参数附加的应用程序信息用来传递给动画代理消息
2、延时动画时间(秒)
[UIView setAnimationDuration:1]; //动画持续时间(秒)
3、设置动画曲线,控制动画速度
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
4、设置动画方式,并指出动画发生的位置
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; 
5、 设置动画代理
[UIView setAnimationDelegate:self];
6、 动画结束后调用的方法,注意设置次方法之前要先设置代理
[UIView setAnimationDidStopSelector:@selector(stop)];
7、 提交动画
[UIView commitAnimations];
二、交换本视图控制器中2个view位置
1、创建动画
[UIView beginAnimations:@"animation" context:nil];
2、动画持续时间
[UIView setAnimationDuration:1];
3、动画曲线
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
4、交换位置
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];//交换位置
5、在commitAnimations消息之前,可以设置动画完成后的回调,设置方法是:
[UIView setAnimationDidStopSelector:@selector(animationFinish:)];
三、使用:CATransition
1、创建动画
CATransition *ansition = [CATransitionanimation];
2、动画持续时间
ansition.duration = 2;
3、 动画循环次数
ansition.repeatCount = 2;
4、 设置动画类型
ansition.type = @"cameraIrisHollowOpen";
5、 设置动画方向
ansition.subtype = kCATransitionFromLeft;
6、设置动画代理
ansition.delegate = self;
7、替换
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
8、添加动画
[view.layeraddAnimation:ansition forKey:@"12"];
9、animateWithDuration
[UIView animateWithDuration:1 animations:^{
         //要执行的操作
         _view.frame = CGRectMake(20, 140, 200, 100);
        }];
       [UIView animateWithDuration:1 animations:^{
            //要执行的操作
        } completion:^(BOOL finished) {
            动画结束
        }];
(1)transition.type 的类型可以有
 淡化、推挤、揭开、覆盖
NSString * const kCATransitionFade;
NSString * const kCATransitionMoveIn;
NSString * const kCATransitionPush;
NSString * const kCATransitionReveal;
 
(2)transition.subtype
 也有四种
NSString * const kCATransitionFromRight;
NSString * const kCATransitionFromLeft;
NSString * const kCATransitionFromTop;
NSString * const kCATransitionFromBottom;
(3)私有的类型的动画类型:
animation.type = @”cube”
animation.type = @”suckEffect”
animation.type = @”oglFlip”//没有方向
animation.type = @”rippleEffect”
animation.type = @”pageCurl”
animation.type = @”pageUnCurl”
animation.type = @”cameraIrisHollowOpen”
animation.type = @”cameraIrisHollowClose”
 
四、具体代码
- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn1.frame = CGRectMake(50, 50, 100, 30);
    //btn1.backgroundColor = [UIColor blackColor];
    [btn1 setTitle:@"动画一" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [btn1 addTarget:self action:@selector(btn1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
   
    UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn2.frame = CGRectMake(120, 50, 100, 30);
    [btn2 setTitle:@"动画二" forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [btn2 addTarget:self action:@selector(btn2) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
   
    UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
    btn3.frame = CGRectMake(190, 50, 100, 30);
    [btn3 setTitle:@"动画三" forState:UIControlStateNormal];
    [btn3 setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [btn3 addTarget:self action:@selector(btn3) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn3];
   
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(375/2.0-50, 300, 100, 100)];
    view.tag = 1;
    view.backgroundColor = [UIColor greenColor];
    [self.view addSubview:view];
}

-(void)btn1{
    UIView *view = [self.view viewWithTag:1];
    [UIView beginAnimations:@"1" context:nil];//创建动画
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];//动画曲线
    [UIView setAnimationDelay:0];//延时动画
    [UIView setAnimationDuration:2];//动画持续时间
    [UIView setAnimationRepeatCount:2];//动画循环次数
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view cache:YES];//设置动画效果,以及要执行的view(动画发生位置,此处是view)
    [UIView setAnimationDelegate:self];//设置动画代理
    [UIView setAnimationDidStopSelector:@selector(stop)];//动画结束后调用的方法,注意设置次方法之前要先设置代理
    [UIView commitAnimations];//提交动画
   
}
-(void)btn2{
    UIView *view = [self.view viewWithTag:1];
    CATransition *ansition = [CATransition animation];//创建动画
    ansition.duration = 2;//动画持续时间
    //ansition.repeatCount = 2;//动画循环次数
    ansition.type = @"cameraIrisHollowOpen";//设置动画类型
    ansition.subtype = kCATransitionFromLeft;//设置动画方向
    ansition.delegate = self;//设置动画代理
    [view.layer addAnimation:ansition forKey:@"12"];//添加动画
   
}
-(void)btn3{
    UIView *view = [self.view viewWithTag:1];
    CGPoint center = view.center;
    //放大效果
//    [UIView animateWithDuration:1 animations:^{
//        view.frame = CGRectMake(10, 10, 300, 300);
//        view.center = center;
//       
//    }];
    //放大缩小连续
    [UIView animateWithDuration:1 animations:^{
        view.frame = CGRectMake(10, 10, 300, 300);
        view.center = center;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1 animations:^{
            view.frame = CGRectMake(375/2.0, 300, 100, 100);
            view.center = center;
        } completion:^(BOOL finished) {
            [self btn3];//添加动画
        }];
    }];
   
    //实现缩小和放大

    [UIView animateWithDuration:1 delay:1 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
        view.frame = CGRectMake(10, 10, 300, 300);
        view.center = center;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1 animations:^{
            view.frame = CGRectMake(375/2.0, 300, 100, 100);
            view.center = center;
        }completion:^(BOOL finished) {
            [self btn3];
        }];
    }];
   
}

-(void)stop1{
    NSLog(@"动画停止");
}
-(void)animationDidStart:(CAAnimation *)anim{
    NSLog(@"动画开始");

}

UIView动画的更多相关文章

  1. 转一篇简洁的UIView动画编程方法

    iOS  中的 UIView 动画编程其实还是很简单的,像 CSS3 一样,在给定的时间内完成状态连续性的变化呈现.比如背景色,Frame 大小,位移.翻转,特明度等. 以前我使用的编程方式都是用下面 ...

  2. UIView动画效果

    做出UI界面,实现程序功能,是重中之重,但是通过动画提升使用体验,一般人应该不会拒绝吧. 那么问题又来了,怎么做? 一: 稳扎稳打: 一步一步来吧,毕竟,心急吃不了热豆腐. 1.开启一个动画 2,设置 ...

  3. 核心动画和UIView动画的区别

    核心动画和UIView动画的区别 1.核心动画制作用在Layer 2.核心动画的修改的属性都是假象,他的真实位置没有发生变化()

  4. 个人学习对UIView动画的总结

    我的博客之前已经开通五个月了,但是一直没有写东西.一是不敢写,二是也不知道写啥.毕竟是一个刚刚入行大半年的菜鸟,现在总想通过各种办法提高自己.之前总感觉用到一些东西,只是当时搞懂了一点,加上并没有总结 ...

  5. UIView动画学习笔记

    UIView的动画是通过修改控件的属性来达到动画的效果,如:渐变, 移动. 废话不多说,直接上代码: - (void)loadView{ [super loadView]; _leftView = [ ...

  6. iOS动画篇:UIView动画

    iOS的动画效果一直都很棒很,给人的感觉就是很炫酷很流畅,起到增强用户体验的作用.在APP开发中实现动画效果有很多种方式,对于简单的应用场景,我们可以使用UIKit提供的动画来实现. UIView动画 ...

  7. iOS之UIview动画

    一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画支持 执行动画所需要的工作由UIView类自动完成, ...

  8. iOS - UIView 动画

    1.UIView 动画 核心动画 和 UIView 动画 的区别: 核心动画一切都是假象,并不会真实的改变图层的属性值,如果以后做动画的时候,不需要与用户交互,通常用核心动画(转场). UIView ...

  9. iOS 动画总结—UIView动画

    1.概述 UIKit直接将动画集成到UIView类中,实现简单动画的创建过程.UIView类定义了几个内在支持动画的属性声明,当这些属性发生改变时,视图为其变化过程提供内建的动画支持. 执行动画所需要 ...

随机推荐

  1. ELK日志管理之——kibana部署

    1.kibana安装 [root@localhost ~]# wget https://download.elastic.co/kibana/kibana/kibana-4.1.1-linux-x64 ...

  2. 【译】RabbitMQ:远程过程调用(RPC)

    在教程二中,我们学习了如何使用工作队列在多个工作线程中分发耗时的任务.但如果我们需要去执行远程机器上的方法并且等待结果会怎么样呢?那又是另外一回事了.这种模式通常被称为远程过程调用(RPC). 本教程 ...

  3. 基类用的this指针

    结论:基类构造函数中的this指针指向的是派生类的对象 测试代码: #include <iostream> using namespace std; class father; fathe ...

  4. HTML5 CSS3学习

    HTML5 CSS3学习 :http://www.1000zhu.com/course/css3/ HTML5 相关书籍:   http://www.html5cn.com.cn/news/gdt/2 ...

  5. RFC2119:表示要求的动词(转)

    RFC(Request For Comments)指的关于互联网标准的正式文件,它们的内容必须写得非常清楚. 表达的时候,必须严格区分哪些是"建议"(suggestion),哪些是 ...

  6. JSTL和EL

    JSTL和EL 1.EL表达式总是放在大括号里,而且前面有一个美元符前缀. person.name2.相似点:(1).都可以让我们在静态内蓉中插入动态信息.EL:室外温度是{emp}度 JSP:室外温 ...

  7. module.export和export

    module.exports 和 exports 是引用到的同一个对象,类似下面代码所示(为了举例,不是完全的正确): var module.exports = {};        var expo ...

  8. Rails中用CSV导出中文真心有技巧

    require 'csv' class PartRequestsController < ApplicationController def render_csv_header(filename ...

  9. jQuery选择器引擎和Sizzle介绍

    一.前言 Sizzle原来是jQuery里面的选择器引擎,后来逐渐独立出来,成为一个独立的模块,可以自由地引入到其他类库中.我曾经将其作为YUI3里面的一个module,用起来畅通无阻,没有任何障碍. ...

  10. python核心编程(第二版)习题

    重新再看一遍python核心编程,把后面的习题都做一下.