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

這是動畫的解決方案只是移動和旋轉層,

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

這對你很好。你可以做到。

祝你好運!