【发布时间】:2010-04-08 10:20:35
【问题描述】:
我正在尝试实现一个 uiview 绘制的图形。有 3 个 UIView 可以为左/右幻灯片设置动画。问题是,我无法取消 UIView 动画。所以我用CALayer替换了UIViews。现在,问题是 CALayer 是否适用于此?像这样在CALayer上画画正常吗?以及为什么在我操作框架属性时 CALayer 会这么慢。
CGRect frame = curve.frame;
frame.origin.x -= diffX;
[curve setFrame:frame];
有其他选择吗?
附:我是一个德国人。有错误请见谅。
我使用 CATransaction 获得动画,但现在我将使用 CABasicAnimation 为 x 移动设置动画。期望layer的位置回到之前的x没问题。
CABasicAnimation *theAnimation;
theAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
theAnimation.delegate = self;
theAnimation.duration = 1.0;
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
CGPoint position = [[curves objectAtIndex:i]position];
position.x = [[curves objectAtIndex:i]position].x - diffX;
[theAnimation setToValue:[NSValue valueWithCGPoint:position]];
[[curves objectAtIndex:i] addAnimation:theAnimation forKey:[NSString stringWithFormat: @"translate.x.%d", index]];
位置改变了位置(例如 xStart = 100, xEnd = 200),但是当动画结束时,图层会回到起点 x(例如 x = 100)。 这正常吗?我该如何解决这个问题,结束位置不再改变? 我尝试更改 removeOnComplete 属性,但没有效果。
希望得到帮助。
马库斯
【问题讨论】:
标签: iphone animation uiview drawing calayer