2014-03-06 6 views
0

원형 CAShapeLayer를 축소하려고하지만 키 경로 '경로'를 사용하면 작동하지 않는 것 같습니다.CAShapeLayer 경로 애니메이션 - 원주 축소

CGPathRef startPath = [UIBezierPath bezierPathWithOvalInRect:startRect].CGPath; 
CGPathRef endPath = [UIBezierPath bezierPathWithOvalInRect:CGRectInset(startRect, 15, 15)].CGPath; 

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"]; 
animation.duration   = 1.0; 
animation.fromValue   = (__bridge id)startPath; 
animation.toValue   = (__bridge id)endPath; 
animation.autoreverses  = YES; 
animation.repeatCount  = CGFLOAT_MAX; 
animation.timingFunction = [CAMediaTimingFunction functionWithControlPoints:0.6 :0.3 :0.8 :0.45]; 

//circleLayer is a CAShapeLayer 
[self.circleLayer addAnimation:animation forKey:@"pathAnimation"]; 

나는 내가, 말, 애니메이션하려고 불투명도 또는 변환하고 경우 거의 동일한 코드가 잘 작동하는 것 같다 때문에 경로 애니메이션이 어떻게 작동하는지에 대해 오해 할 생각합니다.

아이디어가 있으십니까?

+0

내 마음에, 나는 틀린 것을 발견 할 수 없다. 나는 [매우 유사한 코드] (http://stackoverflow.com/a/18683845/608157)를 사용할 수있게되었습니다. 따라서, 두 경로가 합리적이고 작동하는지 확인하십시오 (주로 startRect가 그처럼 삽입 될만큼 충분히 큰지 확인하십시오). 단순히 원형 레이어에 endPath를 지정하고 애니메이션없이 작동하는지 확인하여이를 테스트 할 수 있습니다. –

+0

'startRect'는 무엇입니까? 30x30보다 작 으면 삽입 할 때 CGRectZero가되므로 'endPath'가 정의되지 않을 수 있습니다. 그 중 일부는 완벽하기 때문에. – Cyrille

답변

1

나는 최근에 같은 질문을 던지고 원을 만들어 CGAffineTransform을 애니메이션화하여 해결했습니다. 레이어가 원 인보기에서 나는 간단하게 사용했습니다.

CGAffineTransform transform = CGAffineTransformIdentity; 
transform = CGAffineTransformScale(transform, scaleX, scaleY); 

[UIView animateWithDuration: 0.5 animations: ^{ 
    self.transform = transform; 
}]; 

희망이 있습니다.

관련 문제