2016-06-07 4 views
0

저는 CAShape 레이어에 애니메이션을 적용하려고 시도했지만 올바르게 만들지 못했습니다. 레이어가 있습니다. 다음과 같이 UIView 하위에서 난의 CALayer을 만들 -CAShapeLayer의 애니메이션을 확장합니다.

CAShapeLayer *shape1 = [CAShapeLayer layer]; 
shape1.fillColor = [[UIColor clearColor] CGColor]; 
shape1.strokeColor = [[UIColor purpleColor] CGColor]; 

CGRect frame1 = CGRectMake(13, 13, self.bounds.size.width - 26, self.bounds.size.height - 26); 
shape1.frame = frame1; 
shape1.position = CGPointMake(0,0); 
shape1.anchorPoint = CGPointMake(self.tableContainerView.frame.size.width/2.0, 
           self.tableContainerView.frame.size.height/2.0); 
shape1.path = [self pathForFrame:frame1]; 
shape1.strokeEnd = 0.0f; 
shape1.lineWidth = 1.0; 

[self.layer addSublayer:shape1]; 

가 나는 중심을 유지하면서 초기보다 약간 더 큰 보이는 곳 일부에 도달 할 수 있도록 그것을 애니메이션을 적용 할,이 곳 효과를 확대 만들 것입니다. 내 스케일링 애니메이션 코드는 -

CABasicAnimation *animation2 = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 

//animation2.fromValue = [NSValue valueWithCATransform3D:CATransform3DIdentity]; 
animation2.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.1)]; 
animation2.repeatCount = 1; 
animation2.removedOnCompletion = NO; 
animation2.fillMode = kCAFillModeForwards; 
animation2.duration = 10; 
animation2.beginTime = CACurrentMediaTime() + 4; 
[shape1 addAnimation:animation2 forKey:nil]; 

입니다. 미리 감사드립니다.

+0

중위는이 애니메이션 작업을 UIView의에 모양 레이어를 추가하고, 대신에 일을하기 위해 [shape1의 addAnimation : animation2 forKey : "transform.scale"@] 시도 [view.layer addAnimation : animation2 forKey : @ "transform.scale"]; –

+0

질문이 수정되었습니다. 보기에 이미 모양이 추가되었습니다 (self.layer가 그렇게하고 있습니다). 이득을 분석하십시오. – Avi

답변

0

CAKeyFrameAnimation을 사용하면 애니메이션을보다 잘 제어 할 수 있습니다.

당신은 간단하게 수행 할 수 있습니다

CAMediaTimingFunction *linearTiming = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 
CAKeyframeAnimation *scaleXAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.scale.x"]; 
    scaleXAnimation.duration = 0.300; 
    scaleXAnimation.values = @[@(0.100), @(0.120), @(0.140), @(0.160)]; 
    scaleXAnimation.keyTimes = @[@(0.000), @(0.333), @(0.667), @(1.000)]; 
    scaleXAnimation.timingFunctions = @[linearTiming, linearTiming, linearTiming]; 
    scaleXAnimation.beginTime = 0; 
    scaleXAnimation.fillMode = kCAFillModeBoth; 

    [[self.yourView layer] addAnimation: scaleXAnimation forKey:@"ScaleUp_ScaleX"]; 

    //or if you are subclassing the uiview 

    [[self layer] addAnimation: scaleXAnimation forKey:@"ScaleUp_ScaleX"]; 
관련 문제