我是iOS开发人员,最近我安装了最新的iOS 6进行测试.当我遇到邮件拉动刷新动画时,我决定尝试自己实现它.我试图使用带有UIBezierPath的CAShapeLayer来创建可以向前拖动的相同椭圆形状.并且为了使向下部分向下伸展,我试图使用添加两个控制点的曲线并应用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"]; }
解决方法
iOS 6 Mail中的pull-to-refresh控件是任何应用程序都可以使用的标准UIKit控件:请参阅UITableViewController上的
refreshControl
属性和
UIRefreshControl
类. (另请注意,您可以通过为表视图控制器选择“Refreshing – > Enabled”在XCode 4.5上的IB中设置一个.)
不过,如果您要部署到iOS 5或更早版本,ODRefreshControl是一个不错的选择.