先来看看效果吧

整个核心动画就不多做介绍了,随便一搜就能有很多很详细的解释,主要使用以下四种

CABasicAnimation          //经典动画
CAKeyframeAnimation //关键帧动画
CATransition //转场动画
CAAnimationGroup //组动画

分析下本次demo的动画构成

主要动画是对音频控制面板的操作。

  • 分解

    • 看做两个view 一个是播放面板的小圆 一个是整个控制面板
    • 播放面板的曲线运动 使用核心动画中的 CAKeyframeAnimation
    • 播放面板的变大缩小、控制面板消失出现 使用CABasicAnimation并加入组动画序列CAAnimationGroup
    • 歌曲信息面板的消失和出现

bounds动画

对播放面板进行变大和变小,下面是变小,变大同理。

//startView变小
- (void)startViewChangeSmaller { //设置一组动画
//变小
CABasicAnimation *animation1 = [[CABasicAnimation alloc] init];
animation1.keyPath = @"bounds";
animation1.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, kStartRadius*2, kStartRadius*2)];
//变圆
CABasicAnimation *animation2 = [[CABasicAnimation alloc] init];
animation2.keyPath = @"cornerRadius";
animation2.toValue = [NSNumber numberWithFloat:kStartRadius];
//加入组动画
CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
group.animations = @[animation1,animation2];
group.removedOnCompletion = NO;
group.fillMode = kCAFillModeForwards;
group.duration = kAnimationDuration;
group.delegate = self;
[self.startView.layer addAnimation:group forKey:nil];
self.layer.masksToBounds = YES; [self performSelector:@selector(startViewBackAnimation) withObject:nil afterDelay:kAnimationDuration];
}

曲线动画

这里我们使用的是贝塞尔曲线 先说代码

//通过曲线路径将startView移到中间
- (void)startViewToCenter { //设置贝塞尔曲线路径动画
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:self.startView.center];
[path addCurveToPoint:CGPointMake(self.frame.size.width/2, self.frame.size.height/2 ) controlPoint1:CGPointMake(self.frame.size.width - kStartRadius, 0 ) controlPoint2:CGPointMake(self.frame.size.width * 1.3, self.frame.size.height/2)];
CAKeyframeAnimation *anmiation0 = [CAKeyframeAnimation animationWithKeyPath:@"position"];
anmiation0.path = path.CGPath;
anmiation0.duration = kAnimationDuration;
anmiation0.removedOnCompletion = NO;
anmiation0.fillMode = kCAFillModeForwards;
[self.startView.layer addAnimation:anmiation0 forKey:nil];
[self performSelector:@selector(startViewChangeAnimation) withObject:nil afterDelay:1];
}

这里就要提到贝塞尔曲线的控制点了,这里有个简单的方法去定义曲线。

  • 打开PS 或者其他制图软件
  • 使用钢笔画一条线,通过拖动控制点(锚点)就能更改成曲线的样子
  • 二阶的贝塞尔曲线是有2个控制点

  • 切换钢笔工具为锚点选择工具,我们来拖动锚点,让曲线变成你想要的样子

  • 知道控制点的大概位置这样我们就能定义控制点坐标了。

最后的小贴士:view超出superview的范围了怎么办?

很简单给当前view添加一个响应函数

//响应超出view的事件
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
return YES;
}

再试试看 超出部分的button也可以点击了!

Demo地址

https://github.com/gongxiaokai/CAAnimationDemo

Objective-C 使用核心动画CAAnimation实现动画的更多相关文章

  1. 核心动画 CAAnimation 进阶

    转载自:http://www.cofcool.net/development/2015/06/20/ios-study-note-nine-CoreAnimation/ Core Animation, ...

  2. iOS开发UI篇—核心动画(UIView封装动画)

    iOS开发UI篇—核心动画(UIView封装动画) 一.UIView动画(首尾) 1.简单说明 UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView将为这些改变提供动画 ...

  3. iOS开发UI篇—核心动画(转场动画和组动画)

    转自:http://www.cnblogs.com/wendingding/p/3801454.html iOS开发UI篇—核心动画(转场动画和组动画) 一.转场动画简单介绍 CAAnimation的 ...

  4. 核心动画基础动画(CABasicAnimation)关键帧动画

    1.在iOS中核心动画分为几类: 基础动画(CABasicAnimation) 关键帧动画(CAKeyframeAnimation) 动画组(CAAnimationGroup) 转场动画(CATran ...

  5. iOS:核心动画之关键帧动画CAKeyframeAnimation

    CAKeyframeAnimation——关键帧动画 关键帧动画,也是CAPropertyAnimation的子类,与CABasicAnimation的区别是: –CABasicAnimation只能 ...

  6. iOS:核心动画之基本动画CABasicAnimation

    基本动画,是CAPropertyAnimation的子类 属性说明: fromValue:keyPath相应属性的初始值 toValue:keyPath相应属性的结束值 动画过程说明: 随着动画的进行 ...

  7. 核心动画(UIView封装动画)

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

  8. iOS核心动画以及UIView动画的介绍

    我们看到很多App带有绚丽狂拽的特效,别出心裁的控件设计,很大程度上提高了用户体验,在增加了实用性的同时,也赋予了app无限的生命力.这些华丽的效果很多都是基于iOS的核心动画原理实现的,本文介绍一些 ...

  9. ios开发核心动画七:核心动画与UIView动画的区别

    /** UIView与核心动画区别?(掌握) 1.核心动画只作用在layer. 2.核心动画看到的都是假像,它并没有去修改UIView的真实位置. 什么时候使用核心动画? 1.当不需要与用户进行交互, ...

随机推荐

  1. IntelliJ IDEA提示:Error during artifact deployment. See server log for details.

    IntelliJ IDEA-2017.1.1 tomcat-8.5.13   问题:在IntelliJ IDEA中使用tomcat部署web app时,提示:Error during artifact ...

  2. An internal error occurred during: "Launching New_configuration"

    问题: 点击运行时eclipse报错如下: An internal error occurred during: "Launching New_configuration". Pa ...

  3. 动态分配数组(new)和用随机数赋值(rand)

    #include <iostream>#include <ctime>#include <cstdlib>using namespace std; int main ...

  4. 解决ionic在Android和iOS的一些样式上的冲突

    //设置默认返回按钮的文字 $ionicConfigProvider.backButton.previousTitleText(false).text('返回'); // 设置全局 $http 超时 ...

  5. App测试札记

    App测试札记 测试应该收集信息 测试应该问问题 测试应该扮演不同角色 测试应该如实反馈 初学者 有哪些可以利用的信息?需求,技术方案,测试设计,现有功能,相关人员 App会在哪些环境下运行 App会 ...

  6. java递归算法实现 数字人民币大写转换

    最近穷死了 ,没钱吃饭ing 写点钱给自己吧!public class Test{ public static String getChar(long a){ int b = (int)a; Map ...

  7. 【译】Reflection.Emit vs. CodeDOM

    原文:http://ayende.com/blog/1606/reflection-emit-vs-codedom Both technologies allow you to generate ex ...

  8. 微信js-sdk接口的使用及ios深坑

    最近再做微信公众号开发,涉及到手机上传图片和拍照的功能. 思路一:使用<input type="file" name="pic" id="pic ...

  9. jquery一次绑定多个元素事件

    jquery一次绑定多个元素事件 $(".peoplenum,input[name$='otherAmount'],#aa,#bb").bind("change" ...

  10. PHP中小小的header函数

    不废话,直接说功能 1.重定向,语法: header("location:http://www.lemon-x.ga"); file_put_contents("./te ...