2013-10-31 4 views
0

UIScrollViewUIBezierPath을 그려야합니다. 시작점에서 끝점까지 경로를 그리는 애니메이션을 만들었지 만, 원하는 애니메이션이 아닙니다.UIBezierPath 펄스 애니메이션

UIBezierPath *linePath = [UIBezierPath bezierPath]; 
    [linePath moveToPoint:startPoints]; 
    [linePath addLineToPoint:endPoints; 


    //shape layer for the line 
    CAShapeLayer *line = [CAShapeLayer layer]; 
    line.path = [linePath CGPath]; 
    // line.fillColor = [[UIColor blackColor] CGColor]; 
    line.strokeColor = [[colors objectAtIndex:i] CGColor]; 
    line.lineWidth = 5; 
    // line.contents = (id)[[UIImage imageNamed:@"Mask.png"] CGImage]; 
    // line.contentsGravity = kCAGravityCenter; 



    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; 
    pathAnimation.duration = 3.0; 
    pathAnimation.fromValue = @(0.0f); 
    pathAnimation.toValue = @(1.0f); 
    pathAnimation.repeatCount = HUGE_VAL; 
    [line addAnimation:pathAnimation forKey:@"strokeEnd"]; 

나는 contents에 모양 레이어를 추가하는 시도했지만 나는 애니메이션에 나쁜입니다. 달성하고자하는 효과는 "슬라이드 잠금 해제"와 동일한 애니메이션 또는 펄스하는 경로입니다.

나는 slide-to-unlock의 답변으로 같은 일을 시도했다하지만이 dooing 결국

답변

1

을 관리 할 수없는 것 :

UIBezierPath *linePath = [UIBezierPath bezierPath]; 
[linePath moveToPoint:startPoints]; 
[linePath addLineToPoint:endPoints]; 

//gradient layer for the line 


CAGradientLayer *gradient = [CAGradientLayer layer]; 
gradient.frame = CGRectMake(0, 0, 150.0, 1.0); 
gradient.cornerRadius = 5.0f; 
gradient.startPoint = CGPointMake(0.0, 0.5); 
gradient.endPoint = CGPointMake(1.0, 0.5); 
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor],(id)[[UIColor whiteColor] CGColor],(id)[[UIColor blueColor] CGColor],(id)[[UIColor clearColor] CGColor], nil]; 
[scrollViewContent.layer addSublayer:gradient]; 



CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
anim.path = [linePath CGPath]; 
anim.rotationMode = kCAAnimationRotateAuto; 
anim.repeatCount = 0; 
anim.duration = 1; 
[gradient addAnimation:anim forKey:@"gradient"];