首页 > 其他分享 >iOS7中UIView的animateKeyframesWithDuration方法讲解

iOS7中UIView的animateKeyframesWithDuration方法讲解

时间:2023-02-07 10:04:29浏览次数:39  
标签:动画 relativeDuration self animateKeyframesWithDuration 3.0 animations iOS7 UIView


在iOS7中,给UIView添加了一个方法用来直接使用关键帧动画而不用借助CoreAnimation来实现,那就是animateKeyframesWithDuration

以下是使用源码:

//
// ViewController.m
//
// Created by YouXianMing on 14/11/26.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
[self runAnimateKeyframes];
}

- (void)runAnimateKeyframes {

/**
* relativeDuration 动画在什么时候开始
* relativeStartTime 动画所持续的时间
*/

[UIView animateKeyframesWithDuration:6.f
delay:0.0
options:UIViewKeyframeAnimationOptionCalculationModeLinear
animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 // 相对于6秒所开始的时间(第0秒开始动画)
relativeDuration:1/3.0 // 相对于6秒动画的持续时间(动画持续2秒)
animations:^{
self.view.backgroundColor = [UIColor redColor];
}];

[UIView addKeyframeWithRelativeStartTime:1/3.0 // 相对于6秒所开始的时间(第2秒开始动画)
relativeDuration:1/3.0 // 相对于6秒动画的持续时间(动画持续2秒)
animations:^{
self.view.backgroundColor = [UIColor yellowColor];
}];
[UIView addKeyframeWithRelativeStartTime:2/3.0 // 相对于6秒所开始的时间(第4秒开始动画)
relativeDuration:1/3.0 // 相对于6秒动画的持续时间(动画持续2秒)
animations:^{
self.view.backgroundColor = [UIColor greenColor]; }];

}
completion:^(BOOL finished) {
[self runAnimateKeyframes];
}];
}

@end



细节之处:


[img]http://dl2.iteye.com/upload/attachment/0118/6434/1e7dc9c7-8da1-3179-8333-978ed3a30b88.png[/img]


标签:动画,relativeDuration,self,animateKeyframesWithDuration,3.0,animations,iOS7,UIView
From: https://blog.51cto.com/u_15955464/6041274

相关文章

  • 详解 CALayer 和 UIView 的区别和联系
    前言前面发了一篇iOS面试的文章,在说到UIView和CALayer的区别和联系的时候,被喵神指出没有切中要点,所以这里就CALayer和UIView这个问题重新整理了下。这里会先分条......
  • 《iOS开发指南》第二版 iOS7版-源码-样章-目录,感谢大家一直以来的支持
    目录:​基础篇​1开篇综述​1.1iOS概述21.1.1iOS介绍21.1.2iOS7新特性21.2开发环境及开发工具31.3本书中的约定41.3.1案例代码约定51.3.2......
  • WWDC 2013 Session笔记 - iOS7中的ViewController切换
    这是我的WWDC2013系列笔记中的一篇,完整的笔记列表请参看​​这篇总览​​​。本文仅作为个人记录使用,也欢迎在​​许可协议​​​范围内转载或使用,但是还烦请保留原文链接,谢......
  • 设置UIView的图片
    //自定义的UIViewBackView*backView=[[BackViewalloc]initWithFrame:CGRectMake(SCREEN_HEIGHT-130,50,91,34)];//把图片转为颜色UIColor*bgColor=[UIColorcolorWi......
  • UIView翻转效果实现(转)
    新建一个view-based模板工程,在ViewController文件中添加下面的代码,即可实现翻转效果;-(void)viewDidLoad{[superviewDidLoad];//需要翻转的视图UIView*parentView......
  • UIView Animation 动画学习总结
    目录一、前言二、UIViewAnimation2.1简单动画2.2关键帧动画2.3View的转换三、CALayerAnimation3.1基本动画(CABasicAnimation)3.2关键帧动画(CAKeyframeAnimation)3.3......