2014-03-01 4 views
1

UIBezierPath를 따라 애니메이션을 적용하는 방법에 대한 예제가 많이 있습니다. 하지만 UIBezierPath의 appendPath 만 애니메이션으로 만드는 방법을 알 수는 없습니다. 내 경우iOS - UIBezierPath의 'appendPath'만 애니메이션화하십시오.

난 다음 예제를 가지고 :

// Create path from view controller 
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect: 
         CGRectMake(0, 0, tutorialController.bounds.size.width, 
           tutorialController.bounds.size.height) cornerRadius:0]; 

// Create circle path 
UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(x, y, 2.0*radius, 2.0*radius) cornerRadius:radius]; 
[path appendPath:circlePath]; 
[path setUsesEvenOddFillRule:YES]; 

// Create spot layer 
spotLayer = [CAShapeLayer layer]; 
spotLayer.path = path.CGPath; 
spotLayer.fillRule = kCAFillRuleEvenOdd; 
spotLayer.fillColor = [UIColor blackColor].CGColor; 
spotLayer.opacity = 0.90; 

그래서 기본적으로 자사의 구형 영역의 내부 원과 나는 이제 원을 애니메이션을 적용 할. 모든 시도에서 rect도 움직였다. 여기

은 (내가 경로

CGPoint pathStart = CGPointMake(96.000000, 226.000000); 
CGPoint pathEnd = CGPointMake(120.000000, 300.000000); 

[circlePath moveToPoint:pathStart]; 
[circlePath addLineToPoint:pathEnd]; 

CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
anim.path = circlePath.CGPath; 
anim.duration = 5.0; 
anim.calculationMode = kCAAnimationPaced; 
[spotLayer addAnimation:anim forKey:@"bezierPathAnim"]; 

"함께"애니메이션 할 수 있습니다하지만 난 내 원 경로를 이동, 내가 뭘하고 싶은 것입니다 ... 원하는 것이 아니다 방법, 내 예이다 애니메이션을 통해 사각형 경로의 추가 경로)

누구에게 아이디어가 있습니까?

안부

+0

정확히 코드의 "애니메이션"부분은 무엇입니까? – matt

+0

현재 나에게 맞는 것은 없습니다. 따라서 CAKeyframeAnimation을 사용하여 경로를 따라 애니메이션을 만들 수 있습니다. –

+0

왜 직사각형 패스를 포함하고 다른 하나는 원 경로를 포함하는 두 개의 모양 레이어를 만들고 그 중 하나만 애니메이션으로 만듭니다. – matt

답변

0

I 여기

:-) 내 문제를 해결 용액은 ... 모든

// If there is an old path animate to the new path 
if(oldPath != nil){ 
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"path"]; 
    [anim setFromValue:(__bridge id)oldPath]; 
    [anim setToValue:(__bridge id)[path CGPath]]; 
    [anim setDuration:0.3]; 
    [anim setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
    [spotLayer addAnimation:anim forKey:@"path"]; 
} 

우선 난 oldpath는 (시작점)를 유지하고으로 애니메이션화 새로운 설정된 경로입니다.

관련 문제