How to make one View object move according the ...

本文介绍如何在非游戏应用程序中实现路径动画效果。通过创建可变路径、定义起点和添加路径点数据,最终利用Core Animation使对象沿指定路径移动。

Let the image object move according the slot we have generated is a common feature in the game.But we should get this feature in the non-game app.So how to do it?

So follow me...

- Generate the path you want like this:

CGMutablePathRef path = CGPathCreateMutable();
-Then move to the start point you want:

CGPathMoveToPoint(path, NULL, startPoint.x, startPoint.y);
the startPoint is your first point.

- Add all the point data to path

CGPathAddLineToPoint(path, NULL, tempPoint.x, tempPoint.y);
- Make object moving

[self.layer addAnimation:[self animation: path] forKey:@"position"];
self.layer.needsDisplayOnBoundsChange = YES;
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
path is the path you have made.

More information you can look this demo:

http://www.cocoachina.com/bbs/read.php?tid=11425&keyword=%C2%B7%BE%B6%7C%B6%AF%BB%AD%3C/p%3E

But you should modify the code to meet your requirement.

Thanks,

Blues










转载于:https://my.oschina.net/u/913344/blog/133318

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值