我是一名 iOS 开发人员,最近我在测试中安装了最新的 iOS 6。当我遇到邮件拉动刷新动画时,我决定尝试自己实现它。我尝试将 CAShapeLayer 与 UIBezierPath 一起使用来创建相同的椭圆形,该椭圆形可以向下拖动。为了让下半部分向下拉伸,我尝试使用带有两个控制点的添加曲线并应用 CABasicAnimation。但不幸的是,结果并不像我预期的那样。由于拉伸的线条内部有点椭圆形。我想椭圆形动画必须与其他类有关。如果有人能在这里引导我提出一些想法,我将不胜感激。非常感谢
- (UIBezierPath *)createCircleForRect:(CGRect)bRect
{
UIBezierPath *circle = [UIBezierPath bezierPath];
CGFloat rectWidth = bRect.size.width;
CGFloat rectHeight = bRect.size.height;
minSize = MIN(rectWidth, rectHeight);
//center = CGPointMake(minSize/2.0f, minSize/2.0f);
CGFloat radius = minSize/2.0f - 5.0f;
startPointOffset = center.x - radius;
if(startPointOffset == 5.0f)
testVal = 0;
else
testVal += startPointOffset;
NSLog(@"startPointOffset =>> %f", startPointOffset);
NSLog(@"radius =>> %f", radius);
NSLog(@"after center =>> %f, %f", center.x, center.y);
[circle addArcWithCenter:center radius:radius startAngle:DEGREES_TO_RADIANS(0) endAngle:DEGREES_TO_RADIANS(180) clockwise:NO];
[circle moveToPoint:CGPointMake(startPointOffset, center.y)];
[circle addCurveToPoint:CGPointMake(center.x + radius, center.y) controlPoint1:CGPointMake(center.x - radius, rectHeight + 10.0f) controlPoint2:CGPointMake(center.x + radius, rectHeight + 10.0f)];
[circle closePath];
return circle;
}
-(void)startAnimation
{
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"path"];
animation.duration = 1.0;
animation.repeatCount = HUGE_VALF;
animation.autoreverses = YES;
animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
animation.fromValue = (id)roundBPath;
CGRect smallerRect = self.frame;
smallerRect.size.height += 50;
smallerRect.size.width -= 80;
UIBezierPath *newRound = [self createCircleForRect:smallerRect];
animation.toValue = (id)(newRound.CGPath);
[shapeLayer addAnimation:animation forKey:@"animatePath"];
}