2
如果我單擊「鍛鍊」按鈕,我想要顯示紅色圓形動畫並圍繞圖像。我想移動Storyboard
中的另一個班級。我怎樣才能做到這一點?如何在ios中製作圓形動畫
如果我單擊「鍛鍊」按鈕,我想要顯示紅色圓形動畫並圍繞圖像。我想移動Storyboard
中的另一個班級。我怎樣才能做到這一點?如何在ios中製作圓形動畫
使用UIBezierPath
或CAShapeLayer
,就可以實現這一點。我測試了下面的代碼在我的項目之一,並發現它的工作:
- (void)viewDidLoad
{
[super viewDidLoad];
int radius = 50;
CAShapeLayer *circle = [CAShapeLayer layer];
// Make a circular shape
circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius)
cornerRadius:radius].CGPath;
// Center the shape in self.view
circle.position = CGPointMake(CGRectGetMidX(self.view.frame)-radius,
CGRectGetMidY(self.view.frame)-radius);
// Configure the apperence of the circle
circle.fillColor = [UIColor clearColor].CGColor;
circle.strokeColor = [UIColor redColor].CGColor;
circle.lineWidth = 5;
// Add to parent layer
[self.view.layer addSublayer:circle];
// Configure animation
CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
drawAnimation.duration = 5.0;
drawAnimation.repeatCount = 1.0; // Animate only once..
// Animate from no part of the stroke being drawn to the entire stroke being drawn
drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
drawAnimation.toValue = [NSNumber numberWithFloat:1.0f];
// Experiment with timing to get the appearence to look the way you want
drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
// Add the animation to the circle
[circle addAnimation:drawAnimation forKey:@"draw"];
// Do any additional setup after loading the view, typically from a nib.
}
輸出如下:在按鈕的clickevent
放碼,從起點重新開始 – 2014-10-01 12:18:58