7

我是一名 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"];
}
4

2 回答 2

20

iOS 6 Mail 中的 pull-to-refresh 控件是任何应用程序都可用的标准 UIKit 控件:请参阅refreshControl属性 onUITableViewControllerUIRefreshControl类。(另请注意,您可以在 XCode 4.5 的 IB 中通过为表视图控制器选择“Refreshing -> Enabled”来设置一个。)

不过,如果您要部署到 iOS 5 或更早版本,ODRefreshControl是一个不错的选择。

于 2012-09-23T04:57:37.253 回答
5

给你....

https://github.com/Sephiroth87/ODRefreshControl

于 2012-09-23T02:29:02.320 回答