如何搞出像GameCenter中泡泡一样的动画
来源:互联网 发布:万象ol数据库转2008 编辑:程序博客网 时间:2024/04/28 19:33
代码中加了关键注释,不多说了。
效果的话,想象水中气泡上升过程,只不过没有上升,只是摇来摇去。
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. view1 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 40, 40)]; //圆角设置 view1.layer.masksToBounds = YES; view1.layer.cornerRadius = 20; view1.backgroundColor = [UIColor redColor]; [self.view addSubview:view1]; [self AddAniamtionLikeGameCenterBubble];}-(void)AddAniamtionLikeGameCenterBubble{ CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; pathAnimation.calculationMode = kCAAnimationPaced; //动画均匀进行 pathAnimation.fillMode = kCAFillModeForwards; pathAnimation.removedOnCompletion = NO; pathAnimation.repeatCount = INFINITY; //线性运动 pathAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; pathAnimation.duration = 5.0; //除了xy方向的扩大缩小,泡泡的位置按椭圆形轨迹运动 CGMutablePathRef curvedPath = CGPathCreateMutable();// CGRect circleContainer = CGRectInset(view1.frame, view1.bounds.size.width / 2 -10, view1.bounds.size.width / 2 -5); CGRect circleContainer = CGRectMake(200, 200, 10, 5); //该方法 会按给定rect搞出一个内切圆出来,可以是椭圆 CGPathAddEllipseInRect(curvedPath, NULL, circleContainer); pathAnimation.path = curvedPath; //在上面通过creat创建出来的,需要释放 CGPathRelease(curvedPath); [view1.layer addAnimation:pathAnimation forKey:@"CircleAnimation"]; CAKeyframeAnimation *scaleX = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.x"]; scaleX.duration = 1; scaleX.values = @[@1.0, @1.1, @1.0]; scaleX.keyTimes = @[@0.0, @0.5, @1.0]; //无线循环 scaleX.repeatCount = INFINITY; scaleX.autoreverses = YES; //运动时间函数 这个是先快后慢再快 scaleX.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [view1.layer addAnimation:scaleX forKey:@"scaleXAnimation"]; CAKeyframeAnimation *scaleY = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.y"]; scaleY.duration = 1.5; scaleY.values = @[@1.0, @1.1, @1.0]; scaleY.keyTimes = @[@0.0, @0.5, @1.0]; scaleY.repeatCount = INFINITY; scaleY.autoreverses = YES; scaleX.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [view1.layer addAnimation:scaleY forKey:@"scaleYAnimation"];}
0 0
- 如何搞出像GameCenter中泡泡一样的动画
- 游戏中如何实现GameCenter的应用
- Cygwin中如何像在Ubuntu中一样安装软件
- 如何Drupal当中添加像数据库中一样的自增字段?
- Android中如何像 360 一样优雅的杀死后台服务而不启动
- Android中如何像 360 一样优雅的杀死后台服务而不启动
- Android中如何像 360 一样优雅的杀死后台Service而不启动
- 富文本编辑器中如何让一个Div变成像输入框一样可输入的?
- CEditView 中如何像记事本一样自动换行
- vs中如何像vc6一样增加windows消息处理
- 如何像聪明人一样思考?
- 如何设计一个像人的大脑皮层一样的产品?
- Ie7的菜单栏如何像ie6一样置顶?--downmoon
- 如何生成像资源管理器一样的树形目录
- 如何写一个像UIImagePicker一样的自定义图片选择器
- 如何将文章写的像数学一样简洁完备
- 如何让Eclipse的智能提示像VS一样霸气
- 如何使Dialog像Activity一样随心所欲的使用?
- C语言
- jquery one方法实现
- leetcode -- Binary Tree Zigzag Level Order Traversal -- 重点
- 【HTML】 动态修改Href参数
- media="screen"啥意思?
- 如何搞出像GameCenter中泡泡一样的动画
- iOS之CocoaPods安装和使用
- Sping Mvc 学习笔记(一)
- MySQL查询优化:LIMIT 1避免全表扫描【如判断用户是否存在select * from users where username='123' and passwd='123' limit 1】
- tomcat调优
- 学习励志
- 使用Excel实现打印更大幅面
- 27.Which two statements are true regarding tables?
- 【jQuery】使用each()方法遍历元素