2013-10-17 78 views
0

我想用CABasicAnimation畫一個圈,但奇怪的是它的動畫 代碼中顯示了一個橢圓形的是以下幾點:它顯示動畫期間橢圓而不是圓(IOS)

//---------------draw circle 
// Set up the shape of the circle 
int radius = 10; 
CAShapeLayer *circle = [CAShapeLayer layer]; 
// Make a circular shape 
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath; 
// Configure the apperence of the circle 
circle.fillColor = [UIColor redColor].CGColor; 
circle.strokeColor = [UIColor redColor].CGColor; 
circle.lineWidth = 1; 
// Add to parent layer 
[self.view.layer addSublayer:circle]; 
// Configure animation 
CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"]; 
[pathAnimation setFromValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:0 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath]; 
[pathAnimation setToValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:radius*1.2 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath]; 
[pathAnimation setDuration:15.0f]; 
[pathAnimation setRepeatCount:1.0f]; 
[pathAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]]; 
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath; 
[circle addAnimation:pathAnimation forKey:@"changePathAnimation"]; 

哪有我處理它。

+0

什麼ü想從這個代碼實現...? – Spynet

+0

我想動態地畫圓。但奇怪的是,它顯示動畫過程中的橢圓@Spynet – bohan

+0

CABasicAnimation * pathAnimation = [CABasicAnimation animationWithKeyPath:@「path」]; [pathAnimation setFromValue :(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2)radius:10 startAngle:0 endAngle:M_PI * 2順時針:NO] .CGPath]; 試試這個 – Spynet

回答

3

嘗試這樣,

CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"]; 
[pathAnimation setFromValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:10 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath]; 
[pathAnimation setToValue:(id)[UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2 ,self.view.frame.size.height/2) radius:radius*1.2 startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath]; 
[pathAnimation setDuration:15.0f]; 
[pathAnimation setRepeatCount:1.0f]; 
[pathAnimation setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]]; 
circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height/2) radius:radius startAngle:0 endAngle:M_PI*2 clockwise:NO].CGPath; 
[circle addAnimation:pathAnimation forKey:@"changePathAnimation"]; 
+0

但我想要得到從0開始的圓半徑 – bohan

+0

我已經通過將起始半徑值設置爲0.1來解決它,非常感謝。 – bohan