2013-11-11 4 views
1

У меня есть круг, который я оживляю, растущий наружу и становлюсь больше. К сожалению, несмотря на то, что я установил anchorPoint, он не оживляет от центра наружу, он, похоже, блокирует положение вверху слева. Что происходит?CABasicAnimation происходит от верхнего правого, а не от центра

Смотреть это изображение, которое изображает круги от центра,

enter image description here

код

- (void)setLayerProperties { 
    rippleLayer = [[CAShapeLayer alloc] init]; 
    rippleLayer.fillColor = [UIColor clearColor].CGColor; 

    rippleLayer.strokeColor = _Color.CGColor; 
    //rippleLayer.contentsGravity = @"center"; 
    rippleLayer.anchorPoint = CGPointMake(0.5,0.5); 
    rippleLayer.bounds = self.bounds; 

    rippleLayer.path = bezierPath.CGPath; 
    [self.layer addSublayer:rippleLayer]; 
} 

// Now animate the circle outwards 
rippleLayer.opacity = 1; 
CABasicAnimation *scale = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
[scale setFromValue:[NSNumber numberWithFloat:1.0f]]; 
[scale setToValue:[NSNumber numberWithFloat:2.0f]]; 
[scale setRepeatCount:1]; 
[scale setDuration:1.0f]; 
//[scale setRemovedOnCompletion:YES]; 
[scale setFillMode:kCAFillModeForwards]; 

[rippleLayer addAnimation:scale forKey:scale.keyPath]; 
+1

проверить эту нить http://stackoverflow.com/questions/11495956/calayer-cabasicanimation-not-scaling-around-center-anchorpoint? rq = 1 – lionserdar

+0

@ lionserdar Спасибо, у меня уже есть и все мои ограничения - есть ли что-то еще, что мне не хватает? – Chris

ответ

1

Для масштабирования слоя в его центре, вы должны установить position.This слоя может помочь вам

I want to draw a Smooth animations in iOS using CAPropertyAnimations

определить RADIANS (угол) ((угол)/180,0 * M_PI)

CGPoint testCenter = CGPointMake(144.5, 230.0); 
CAShapeLayer *aTestLayer = [CAShapeLayer layer]; 
aTestLayer.path = [UIBezierPath bezierPathWithArcCenter:**CGPointZero** radius:15.0 startAngle:RADIANS(0) endAngle:RADIANS(360) clockwise:YES].CGPath; 
aTestLayer.fillColor = [UIColor clearColor].CGColor; 
aTestLayer.strokeColor = [UIColor whiteColor].CGColor; 
**aTestLayer.position = testCenter;** 
aTestLayer.borderWidth = 2.0; 

[self.view.layer addSublayer:aTestLayer]; 

CABasicAnimation *pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; 
pulse.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]; 
pulse.duration = 2; 
pulse.repeatCount = HUGE_VALF; 
pulse.autoreverses = YES; 
pulse.fromValue = [NSNumber numberWithFloat:1.0]; 
pulse.toValue = [NSNumber numberWithFloat:2.0]; 


[aTestLayer addAnimation:pulse forKey:nil]; 
Смежные вопросы