#import "ViewController.h"
#import <QuartzCore/QuartzCore.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //创建一个
    UIView *view=[[UIView alloc]init];
    view.backgroundColor=[UIColor redColor];
    [self.view addSubview:view];
    view.tag=1001;
    
    //top 200 dowm 200 left 40 right 40
    [view setTranslatesAutoresizingMaskIntoConstraints:NO];
    NSArray *constraintH= [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-40-[view]-40-|" options: 0 metrics:Nil views:NSDictionaryOfVariableBindings(view)];
    NSArray *constraintV=[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-200-[view(>=30)]-200-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(view)];
    [self.view addConstraints:constraintH];
    [self.view addConstraints:constraintV];
    
    UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.view addSubview:button];
    [button setTitle:@"开始动画" forState:UIControlStateNormal];
    [button setTranslatesAutoresizingMaskIntoConstraints:NO];
    NSArray *contraintButtonH=[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-40-[button(>=100)]-40-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(button)];
    NSArray *contraintButtonV=[NSLayoutConstraint constraintsWithVisualFormat:@"V:[button(30)]-20-[view]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(button,view)];
    [self.view addConstraints:contraintButtonH];
    [self.view addConstraints:contraintButtonV];
    [button addTarget:self action:@selector(didClickAnimationButton:) forControlEvents:UIControlEventTouchUpInside];
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)didClickAnimationButton:(UIButton *)button
{
    //获取要承载动画的视图..
    UIView *redView=[self.view viewWithTag:1001];
    /*
    //使用uiview类方法--1
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        //视图的最终状态
        CGFloat r=arc4random()%1000/1000.f;
        CGFloat g=arc4random()%1000/1000.f;
        CGFloat b=arc4random()%1000/1000.f;
        
        redView.backgroundColor=[UIColor colorWithRed:r green:g blue:b alpha:1.0f];
        
        
        //加旋转
//        redView.transform=CGAffineTransformMakeRotation(M_PI_2*r);
        
    } completion:^(BOOL finished) {
        NSLog(@"finished....");
    }];
     */
    
    /*
    //使用UIView类方法2
    //开始设置动画
    [UIView beginAnimations:nil context:nil];
    //设置过渡效果是否从当前状态开始启动,否则为当前视图的最终状态开始启动
    [UIView setAnimationBeginsFromCurrentState:YES];
    //设置过渡效果的进度,慢入慢出,慢入,慢出,线性4中
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    //设置过渡效果对否延迟
    [UIView setAnimationDelay:0];
    //设置过渡效果的过渡时间
    [UIView setAnimationDuration:0.25f];
    //设置过渡效果是否自动恢复
    [UIView setAnimationRepeatAutoreverses:YES];
    //设置过渡效果是否重复出现
    [UIView setAnimationRepeatCount:1.5];
    
    //设置
    [UIView setAnimationDelegate:self];
    [UIView setAnimationWillStartSelector:@selector(animationStart)];
    [UIView setAnimationDidStopSelector:@selector(animationStop)];
    
    
    CGFloat x=arc4random()%100+100;
    CGFloat y=arc4random()%100+100;
    redView.center=CGPointMake(x, y );
    
   // button.center=CGPointMake(x, y );
   // [button layoutIfNeeded];
    //提交过度动画效果
    [UIView commitAnimations];
     
     */
    
    /*
    //使用quartzCore框架内的对象--3
    //实例化过度对象
    CATransition *animation=[CATransition animation];
    //设置过度对象的时间
    animation.duration=0.5f;
    //设置过度对象的类型
    animation.type=kCATransitionFade;
    //设置过度对象的子类型
    //animation.subtype=
    [redView.layer addAnimation:animation forKey:nil];
    redView.layer.opacity=0.0f;//设置透明度
    */
    
    /*
    CABasicAnimation *animation=[CABasicAnimation animationWithKeyPath:@"anchorPoint"];
//    /设置过度对象的时间间隔
    animation.duration=0.5f;
    //设置过度对象的开始值
    animation.fromValue=[NSValue valueWithCGPoint:CGPointMake(0.5, 0.5)];
    animation.toValue=[NSValue valueWithCGPoint:CGPointMake(1.0, 1.0)];
    //将过度对象添加到视图层上
    [redView.layer addAnimation:animation forKey:nil];
    //设置视图层的最终状态
    redView.layer.anchorPoint=CGPointMake(1.0f, 1.0f);
     */
    
    
    
    /*
//    keyframe
    CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
    //设置过度对象时间间隔
    animation.duration=1;
    //设置过度对象的中间过度状态
    CGMutablePathRef path = CGPathCreateMutable();
    CGPathMoveToPoint(path, nil, 110, 200);
    CGPathAddQuadCurveToPoint(path, nil, 150, 250, 200, 200);
    animation.path=path;
    //将过度对象添加到视图
    [redView.layer addAnimation:animation forKey:nil];
     */
    
}

-(void)animationStart
{
    NSLog(@"begin-------------------");
}
-(void)animationStop
{
    NSLog(@"end--++++++++++++++++++++++++++++");
}

IOS 动画的各种实现方法的更多相关文章

  1. ios 动画效果CATransition笔记

    初学ios开发,很多概念还不清楚,所以只有边学边做例子.又怕学了后面忘了前面,因此用自己的博客来纪录自己的学习历程,也是对自己学习不要懈怠做个监督. 刚学ios做动画效果.因为ios封装得很好,实现i ...

  2. (转)iOS动画Core Animation

    文章转载:http://blog.sina.com.cn/s/blog_7b9d64af0101b8nh.html 在iOS中动画实现技术主要是:Core Animation. Core Animat ...

  3. 解析 iOS 动画原理与实现

    这篇文章不会教大家如何实现一个具体的动画效果,我会从动画的本质出发,来说说 iOS 动画的原理与实现方式. 什么是动画 动画,顾名思义,就是能“动”的画.人的眼睛对图像有短暂的记忆效应,所以当眼睛看到 ...

  4. IOS动画隐式,显式,翻页

    //  ViewController.m //  IOS动画0817 // //  Created by 张艳锋 on 15/8/17. //  Copyright (c) 2015年 张艳锋. Al ...

  5. iOS动画篇:UIView动画

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

  6. iOS动画原理

    1. iOS动画原理 本质:动画对象(这里是UIView)的状态,基于时间变化的反应 分类:可以分为显式动画(关键帧动画和逐帧动画)和隐式动画 关键帧和逐帧总结:关键帧动画的实现方式,只需要修改某个属 ...

  7. iOS 动画基础

    原文:http://www.cnblogs.com/lujianwenance/p/5733846.html   今天说一下有关动画的基础,希望能帮助到一些刚接触iOS动画或者刚开始学习iOS的同学, ...

  8. IOS动画总结

    IOS动画总结   一.基本方式:使用UIView类的UIViewAnimation扩展 + (void)beginAnimations:(NSString *)animationID context ...

  9. IOS 动画专题 --iOS核心动画

    iOS开发系列--让你的应用“动”起来 --iOS核心动画 概览 通过核心动画创建基础动画.关键帧动画.动画组.转场动画,如何通过UIView的装饰方法对这些动画操作进行简化等.在今天的文章里您可以看 ...

随机推荐

  1. Valid Palindrome [LeetCode]

    Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignori ...

  2. log4j配置文件的详解

    1.配置根Logger,其语法为: log4j.rootLogger = [ level ] , appenderName, appenderName, … 其中,level 是日志记录的优先级,分为 ...

  3. oracle错误码

    ORA-00001: 违反唯一约束条件 (.) ORA-00017: 请求会话以设置跟踪事件 ORA-00018: 超出最大会话数 ORA-00019: 超出最大会话许可数 ORA-00020: 超出 ...

  4. Android 适配器

     Adapter是连接后端数据和前端显示的桥梁,是数据和UI(View)之间的纽带.     在常见的View(ListView,GridView)等地方都需要用到Adapter.数据.Adapter ...

  5. 怎样打造一个分布式数据库——rocksDB, raft, mvcc,本质上是为了解决跨数据中心的复制

    摘自:http://www.infoq.com/cn/articles/how-to-build-a-distributed-database?utm_campaign=rightbar_v2& ...

  6. Js笔试题之返回只包含数字类型的数组

    如js123ldka78sdasfgr653 => [123,78,653] 一般做法 分析: 1.循环字符串每个字符,是数字的挑出来拼接在一起,不是数字的,就给他空的拼个逗号 2.将新字符串每 ...

  7. android webview 漏洞背后的节操

    by superhei 2013/09/06 [注:本文提到的都是我个人的观点,该行为也是私人行为,与任何组织.公司无关.另:水军请自重!] 一.前言   这两天,一个2+年前的android web ...

  8. ZOJ 3652 Maze 模拟,bfs,读题 难度:2

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4842 要注意题目中两点: 1.在踏入妖怪控制的区域那一刹那,先减行动力,然后才 ...

  9. HDU 4890 One to Four(2014 Multi-University Training Contest 3)

    题意:给定一个长方形网格,要把它切成完全相同4个部分(这里完全相同指可以旋转平移后能重叠).把4个重叠后每个网格对应有四个数字相加,得到一种方案,所有格子中和最小就是该种方案的值,在多种方案中,最后问 ...

  10. 神奇的NOIP模拟赛 T2 LGTB 学分块

    LGTB 学分块 LGTB 最近在学分块,但是他太菜了,分的块数量太多他就混乱了,所以只能分成3 块今天他得到了一个数组,他突然也想把它分块,他想知道,把这个数组分成3 块,块可以为空.假设3 块各自 ...