【问题标题】:CALayer AnimationCALayer 动画
【发布时间】:2011-06-01 17:32:05
【问题描述】:
我是初学者,我正在努力继续熟悉CALayer ...
再次感谢@Alexsander Akers、@DHamrick 和 @Tommy,因为现在我可以歪曲我的 CALayer 了!
看起来像:
我想将我的手指放在灰色UIView(与touchesBegan/touchesMoved/touchesEnded)上,我的“卡片”移动如下:
(例如,如果我向左移动手指)
- 黄牌消失,绿牌出现
- 白色代替绿色
- 红白相间
- 蓝色的红色的
- 然后出现的不是蓝卡而是黑卡...
也许我在做梦,这对我来说很难,但如果你能给我建议,我会接受的!!
谢谢!
【问题讨论】:
标签:
objective-c
core-animation
calayer
【解决方案1】:
您可以像这样使用自定义功能
- (void)moveAndRotateLayer: (CALayer *)layer withDuration:(double)duration degreeX:(double)degreeX y:(int)degreeY angle:(float)angle autoreverseEnable:(BOOL)ar repeatTime:(int)repeat andTimingFunctionType:(NSString *)type
{
// You should type the timing function type as "Liner", "EaseIn", "EaseOut" or "EaseInOut".
// The default option is the liner timing function.
// About these functions, look in the Apple's reference documents.
CAAnimationGroup *theGroup = [CAAnimationGroup animation];
CGPoint movement = CGPointMake(layer.position.x + degreeX, layer.position.y + degreeY);
NSArray *animations = [NSArray arrayWithObjects:[self moveLayers:layer to:movement duration:duration], [self rotateLayers:layer to:angle duration:duration], nil];
theGroup.duration = duration;
theGroup.repeatCount = repeat;
theGroup.autoreverses = ar;
if ([type isEqualToString:@"EaseIn"])
{
theGroup.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseIn];
}
else if ([type isEqualToString:@"EaseOut"])
{
theGroup.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
}
else if ([type isEqualToString:@"EaseInOut"])
{
theGroup.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
}
else
{
theGroup.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
}
theGroup.animations = [NSArray arrayWithArray:animations];
[layer addAnimation:theGroup forKey:@"movingAndRotating"];
}
这是动画仅用于移动和旋转图层的解决方案,
但是,我知道您可以自定义。
这对你很好。你可以做到的。
祝你好运!