【发布时间】:2016-05-27 17:22:20
【问题描述】:
几年前,我使用此代码实现了计时器动画。 是一个可爱的动画,但不适用于 iOS8>
应该会出现一个圆圈,每 0.1 秒丢失一个馅饼,但动画没有开始。它适用于我的 iPhone 5 iOS 7.1
我试图解决它,但 2 小时后我没有解决方案。
有更多 CABasicAnimation 经验的人可以帮助我吗?
谢谢。
这是代码:
//Animazione CRONOMETRO
-(void) startCronometro{
//SetTime
counterStart = TIME;
[sfondoCronometro setImage:[UIImage imageNamed:@"cronoStart.png"]];
maskLayer = [CAShapeLayer layer];
CGFloat maskHeight = sfondoCronometro.frame.size.height;
CGFloat maskWidth = sfondoCronometro.frame.size.width;
CGPoint centerPoint;
centerPoint = CGPointMake(sfondoCronometro.frame.size.width/2, (sfondoCronometro.frame.size.height/2));
//Make the radius of our arc large enough to reach into the corners of the image view.
CGFloat radius = sqrtf(maskWidth * maskWidth + maskHeight * maskHeight)/2;
//Don't fill the path, but stroke it in black.
maskLayer.fillColor = [[UIColor clearColor] CGColor];
maskLayer.strokeColor = [[UIColor blackColor] CGColor];
maskLayer.lineWidth = 25;
CGMutablePathRef arcPath = CGPathCreateMutable();
//Move to the starting point of the arc so there is no initial line connecting to the arc
CGPathMoveToPoint(arcPath, nil, centerPoint.x, centerPoint.y-radius/2);
//Create an arc at 1/2 our circle radius, with a line thickess of the full circle radius
CGPathAddArc(arcPath, nil, centerPoint.x, centerPoint.y, radius/2, 3*M_PI/2, -M_PI/2, NO);
maskLayer.path = arcPath;//[aPath CGPath];//arcPath;
//Start with an empty mask path (draw 0% of the arc)
maskLayer.strokeEnd = 0;
CFRelease(arcPath);
//Install the mask layer into out image view's layer.
sfondoCronometro.layer.mask = maskLayer;
//Set our mask layer's frame to the parent layer's bounds.
sfondoCronometro.layer.mask.frame = sfondoCronometro.layer.bounds;
//Create an animation that increases the stroke length to 1, then reverses it back to zero.
CABasicAnimation *swipe = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
swipe.duration = TIME;
NSLog(@"TIME: %f", swipe.duration);
swipe.delegate = self;
// [swipe setValue:@"string" forKey:@"key"];
swipe.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
swipe.fillMode = kCAFillModeForwards;
swipe.removedOnCompletion = NO;
swipe.toValue = [NSNumber numberWithFloat: 1.0];
[maskLayer addAnimation: swipe forKey: @"strokeEnd"];
}
【问题讨论】:
-
您说“...不适用于 iOS8>”,但没有说 what 不起作用。您发布了一堆代码,但没有任何解释。发生了哪些事情是您没有预料到的,或者没有发生您确实期望的事情? (特别是。)
-
是的,请原谅我。应该出现一个圆圈,每 0.1 秒丢失一个馅饼,但动画没有开始。它适用于我的 iPhone 5 iOS 7.1
标签: ios xcode animation cabasicanimation