繁体   English   中英

CALayer Animation

[英]CALayer Animation

我是初学者,我试图继续熟悉CALayer ...

再次感谢@Alexsander Akers、@DHamrick 和@Tommy,因为现在我可以调整我的CALayer了!

它看起来像:

队长 1

我想在 Gray UIView上移动我的手指(带有touchesBegan / touchesMoved / touchesEnded ),我的“卡片”像这样移动:(例如,如果我向左移动手指)

  • 黄牌消失,绿牌出现
  • 白色代替绿色
  • 红白相间
  • 蓝色的红色的
  • 而不是一张蓝牌,而是出现了一张黑牌……

也许我在做梦,这对我来说很难,但如果你能给我建议,我会接受的!!

谢谢你 !

您可以像这样使用定制的 function

- (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"];
}

这是 animation 的解决方案,仅用于移动和旋转图层,

但是,我知道您可以自定义。

这对你很好。 你可以做到。

祝你好运!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM