2011-06-01 96 views
0

我是初学者,我想继续CALayer熟悉自己...CALayer的动画

再次感谢@Alexsander埃克斯,@DHamrick和@Tommy因为现在我可以扭曲我的CALayer

它看起来像:

capt 1

我想移动我的手指上的灰UIView(与touchesBegan/touchesMoved/touchesEnded)和我的 “卡” 移动是这样的: (对于为例,如果我向左移动了我的手指)

  • 黄牌消失&绿色的看法是地方
  • 白走绿色的地方
  • 红白色
  • 蓝色红色的
  • 和,而不是蓝卡一黑一出现...

也许我是在做梦,它的到对我来说很难,但如果你可以给我建议,我会接受它!

谢谢!

回答

0

您可以使用自定义功能,这样

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

这是动画的解决方案只是移动和旋转层,

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

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

祝你好运!