当前位置:编程学习 > wap >>

iphone动画结束问题

定义2个动画
-(CAKeyframeAnimation *)moveanimation
{
    CGMutablePathRef path=CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL,0,0);
    CGPathAddQuadCurveToPoint(path,NULL, 100, 100, 0, 100);
    CGPathCloseSubpath(path);
    CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.duration=4.0f;
    animation.path=path;
    animation.calculationMode=kCAAnimationCubicPaced;
    animation.delegate=self;
    CFRelease(path);
    return animation;
}
-(CAKeyframeAnimation *)movestraight
{
    CGMutablePathRef path=CGPathCreateMutable();
    CGPathMoveToPoint(path, NULL, 0, 0);
    CGPathAddLineToPoint(path, NULL, 100, 100);
    CGPathAddLineToPoint(path, NULL, 0, 100);
    CAKeyframeAnimation *animation=[CAKeyframeAnimation animationWithKeyPath:@"position"];
    animation.delegate=self;
    animation.duration=4.0f;
    animation.path=path;
    animation.fillMode=kCAFillModeForwards;
    animation.removedOnCompletion=NO;
    CFRelease(path);
    return animation;
}
分别调用他们
[imageView.layer addAnimation:[self movestraight] forKey:@"123"];
[imageView.layer addAnimation:[self moveanimation] forKey:@"234"];
如何再
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
        NSLog(@"123");
}中判断是哪个动画结束了。求详细教育

--------------------编程问答-------------------- when the animation block has finish, you can use
setAnimationDidStopSelector: method.

上API;
Sets the message to send to the animation delegate when animation stops.
+ (void)setAnimationDidStopSelector:(SEL)selector

If you are using a CAAnimation instance, look at the animationDidStop:finished: for its delegate.
your delegate should implement the animation
DidStop:finished: method to be able to detect the animation end.

API如下:
Called when the animation completes its active duration or is removed from the object it is attached to.
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
--------------------编程问答-------------------- 就是说有两个方法,setAnimationDidStopSelector: method 这个方法对于你判断是比较简单好用的。 --------------------编程问答-------------------- 有没有实际的例子饿。
--------------------编程问答-------------------- 有,你自己考虑考虑先⋯⋯
http://www.cocoachina.com/bbs/
搜索一下动画结束⋯⋯
会有很多
--------------------编程问答-------------------- 将animation.tag随便设为不同值,当回调animationDidStop时判断参数(CAAnimation *)anim的tag就可以知道是哪个动画了 --------------------编程问答-------------------- 用anim指针就可以判断啊; 不可能有两个对象指针完全相同。 --------------------编程问答-------------------- 另外,1楼的同样可以。
补充:移动开发 ,  iPhone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,