重要的两个方法:1.动画的数组:animations 2.启动的时间 beginTime

注意:动画组设置了持续时间(duration)可能会导致动画组里面的持续时间不管用

代码如下:

#import "ViewController.h"

@interface ViewController ()

{

CALayer * fllowers;

}

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

[self addBgView];

[self addFllower];

}

点击屏幕开始动画

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

[self addAnimationGroup];

}

背景图

-(void)addBgView{

UIImageView * image = [[UIImageView alloc]initWithFrame:self.view.frame];

image.image = [UIImage imageNamed:@"背景.jpg"];

[self.view addSubview:image];

}

在背景图上添加CALayer(花瓣)

-(void)addFllower{

UIImage * img = [UIImage imageNamed:@"花瓣"];

fllowers = [[CALayer alloc]init];

fllowers.position = CGPointMake(100, 200);

fllowers.bounds = CGRectMake(0, 0, img.size.width, img.size.height);

fllowers.contents = (id)img.CGImage;

[self.view.layer addSublayer:fllowers];

}

#pragma mark -------------添加动画组----------------

-(void)addAnimationGroup{

CAAnimationGroup *group = [CAAnimationGroup animation];

group.animations = @[[self rotationAnimation],[self dropAnimation]];

group.duration = 10;

//    动画开始的时间

//    CACurrentMediaTime() 获得当前的时间

//    从调用这个方法开始,5秒之后 执行这个动画

group.beginTime = CACurrentMediaTime()+5;

group.removedOnCompletion = NO;

group.fillMode = kCAFillModeBoth;

[fllowers addAnimation:group forKey:@"group"];

}

//旋转效果

-(CABasicAnimation *)rotationAnimation{

CABasicAnimation *rotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

rotation.toValue = @(M_2_PI*3);

rotation.removedOnCompletion = NO;

return rotation;

}

//关键帧动画,设置花瓣掉落的曲线

-(CAKeyframeAnimation *)dropAnimation{

CAKeyframeAnimation * drop = [CAKeyframeAnimation animationWithKeyPath:@"position"];

//    drop.path =

CGPathRef pathref = CGPathCreateMutable();

CGPathMoveToPoint(pathref, NULL, fllowers.position.x, fllowers.position.y);

//   CGFloat cp1x, CGFloat cp1y,  设置两个点,在这两个点之间画曲线

//     CGFloat x, CGFloat y 终止点

CGPoint endPoint = CGPointMake(80, 600);

CGPathAddCurveToPoint(pathref, NULL,160 ,280 ,-30 ,500 , endPoint.x, endPoint.y);

drop.path = pathref;

CGPathRelease(pathref);

return drop;

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

二.背景图和花瓣图

         花瓣: 

三.

最新文章

  1. Windows无法安装到这个磁盘。请确保在计算机的BIOS菜单中启用了磁盘控制器
  2. ssh config host
  3. Bootstrap学习笔记系列2-------Bootstrap简单表格处理
  4. HDU 2117 取(2堆)石子游戏【wzf博弈】
  5. Eclipse中启用Oracle jdbc logging
  6. web相关概念
  7. Linux里如何查找文件内容 (转)
  8. drag drop小游戏
  9. oracle中区分audit_file_dest, background_dump_dest, core_dump_dest, user_dump_dest
  10. 用 jQuery Masonry 插件创建瀑布流式的页面
  11. QT添加exe文件的图标LOGO
  12. 网站SEO,HTTP请求的关键数字----6
  13. WPF 快捷方式
  14. 《android开发进阶从小工到专家》读书笔记--网络框架的设计与实现
  15. I used to know
  16. c# 右下角弹出窗口
  17. 【转】Android辅助功能AccessibilityService自动全选择文字粘贴模拟输入
  18. C#_Attribute特性
  19. ui-router 1.0 001 - resolve, component, sref-active
  20. 获取Sqlserver上一句语句执行后受影响的行数@@rowCount

热门文章

  1. iOS block的用法
  2. FreeModbus 精简版本(Only RTU) for M128 (Modbus Slave)
  3. Appium Android定位元素与操作
  4. PHP魔术变量总结
  5. A Mathematician‘s Survival Guide Graduate School and Early Career Development
  6. 【转】linux中的sort命令
  7. PHP函数ip2long转换IP时数值太大产生负数的解决办法
  8. java并行调度框架封装及演示样例
  9. [React Fundamentals] Composable Components
  10. [xml解析]rapidxml读取文件