Tag: cabasicanimation

CABasicAnimation完成1个周期后回到原来的位置

在下一个animation和Objective-C 之前不要将CABasicAnimation返回到原始位置 – animation之后应用更改的CABasicAnimation? 和CABasicAnimation旋转返回到我试过的原始位置 。 below code does,bottom->top->goes left->back to it's original position. bottom->top->goes left->back to its original position. I need bottom->top->goes left.bottom->top->goes left so on… -(void)addUpDownAnimationForButton:(UILabel*)label { CABasicAnimation * bottomAnimation ; bottomAnimation =[CABasicAnimation animationWithKeyPath:@"transform.translation.y"]; [bottomAnimation setValue:@"animation1" forKey:@"id"]; bottomAnimation.delegate = self; [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)]; bottomAnimation.duration = 2.0; bottomAnimation.fromValue = [NSNumber numberWithFloat:13]; bottomAnimation.toValue = [NSNumber numberWithFloat:-7]; […]

animationCALayer背景颜色和更新模型值

我想为我的UIView(在tintColorDidChange )中的一个子图层的backgroundColor改变animation。 我需要从图层的当前背景颜色animation多次到新的色调颜色(每次不同的色调),所以需要更新backgroundColor的模型值(我不能在animation上使用removedOnCompletion = false )。 使用CABasicAnimation我有颜色更改animation工作正常,如果我不更新模型值(但当然animation完成后颜色重置)。 当我尝试更新模型值时,颜色变化立即发生,animation丢失。 我试图禁用隐式animation并使用CATransation更新模型值,但animation仍然丢失。 我如何更新backgroundColor模型的值,并保持我的淡出animation工作? override func tintColorDidChange() { super.tintColorDidChange() let colourAnim = CABasicAnimation(keyPath: "backgroundColor") colourAnim.toValue = self.tintColor.CGColor colourAnim.duration = 1.0 self.spinnerLayer?.addAnimation(colourAnim, forKey: "colourAnimation") CATransaction.begin() CATransaction.setDisableActions(true) self.spinnerLayer?.backgroundColor = self.tintColor.CGColor CATransaction.commit() }

如何获得完美的旋转UIView的X,Y位置在ios中

我正在使用CABasicanimation旋转UIView。 我正在使用这个代码, CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; NSNumber *currentAngle = [CircleView.layer.presentationLayer valueForKeyPath:@"transform.rotation"]; rotationAnimation.fromValue = currentAngle; rotationAnimation.toValue = @(50*M_PI); rotationAnimation.duration = 50.0f; // this might be too fast rotationAnimation.repeatCount = HUGE_VALF; // HUGE_VALF is defined in math.h so import it [CircleView.layer addAnimation:rotationAnimation forKey:@"rotationAnimationleft"]; 在这个我想要完美的X,Y位置,而“UIView”旋转。 如果有人知道请帮助我。 先谢谢你。

主页button被按下时,CABasicAnimation消失

我正在实施一个游戏,其中我有一些CABasicAnimations。 例如,像这样: CABasicAnimation * borddroit = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"]; borddroit.fromValue = [NSNumber numberWithFloat:0.0f]; borddroit.toValue = [NSNumber numberWithFloat:749.0f]; borddroit.duration = t; borddroit.repeatCount = 1; [ImageSuivante2.layer addAnimation:borddroit forKey:@"borddroit"]; 我用这个函数暂停: -(void)pauseLayer:(CALayer*)layer { CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; layer.speed = 0.0; layer.timeOffset = pausedTime; } 当我的应用程序进入后台,因为用户按下home键,animation正确设置暂停,但是当我重新打开我的应用程序,animation已经消失。 我怎么能修好它? 谢谢

将UIButton的背景颜色从WhiteColoranimation到RedColor

我正在试图制作一种颜色脉冲效果animationUIButton背景颜色,使其从颜色(WhiteColor)不断地改变到另一个(RedColor)。 我试图使用CABasicAnimation改变不透明度,但我不能让它与颜色也工作。 CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"]; theAnimation.duration=1.0; theAnimation.repeatCount=HUGE_VALF; theAnimation.autoreverses=YES; theAnimation.fromValue=[NSNumber numberWithFloat:1.0]; theAnimation.toValue=[NSNumber numberWithFloat:0.0]; [BigButton.layer addAnimation:theAnimation forKey:@"animateOpacity"]; 每一个build议,将不胜感激。 谢谢

为什么当我为我的CABasicAnimation设置一个较低的持续时间值时,它会跳转吗?

示例项目: http : //cl.ly/1W3V3b0D2001 我使用CABasicAnimation来创build一个像饼图一样的进度指示器。 类似于iOS 7的应用程序下载animation: animation设置如下: – (void)drawRect:(CGRect)rect { [super drawRect:rect]; CGFloat radius = CGRectGetWidth(self.frame) / 2; CGFloat inset = 1; CAShapeLayer *ring = [CAShapeLayer layer]; ring.path = [UIBezierPath bezierPathWithRoundedRect:CGRectInset(self.bounds, inset, inset) cornerRadius:radius-inset].CGPath; ring.fillColor = [UIColor clearColor].CGColor; ring.strokeColor = [UIColor whiteColor].CGColor; ring.lineWidth = 2; self.innerPie = [CAShapeLayer layer]; inset = radius/2; self.innerPie.path = […]

使用UIImageView图层的边框宽度的颜色填充进度

我有UIImageView,我已经使它成为一个宽度层的圆圈,就像在这个图像: 用户可以更新图片并上传新图片,图片上传时我有一个进度callback。 我想要的是在图像上传时用颜色animation边框,例如当用户点击上传边框从绿色开始,根据进度填充宽度。 我试着用这个代码: CAShapeLayer *circle = [CAShapeLayer layer]; circle.path = [UIBezierPath bezierPathWithArcCenter:CGPointZero radius:27 startAngle:-M_PI_2 endAngle:2 * M_PI – M_PI_2 clockwise:YES].CGPath; circle.fillColor = [UIColor clearColor].CGColor; circle.strokeColor = [UIColor greenColor].CGColor; circle.lineWidth = 4; CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; animation.duration = 10; animation.removedOnCompletion = NO; animation.fromValue = @(0); animation.toValue = @(1); animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; [circle addAnimation:animation […]

CABasicAnimation – 设置开始行程位置

我正在为一个基本的圈子绘制animation。 这工作正常,除了animation开始绘制在3点钟的位置。 有谁知道我可以如何使它在12点开始? self.circle = [CAShapeLayer layer]; self.circle.fillColor = nil; self.circle.lineWidth = 7; self.circle.strokeColor = [UIColor blackColor].CGColor; self.circle.bounds = CGRectMake(0, 0, 200, 200); self.circle.path = [UIBezierPath bezierPathWithOvalInRect:self.circle.bounds].CGPath; [self.view.layer addSublayer:self.circle]; CABasicAnimation *drawAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; drawAnimation.duration = 5.0; drawAnimation.repeatCount = 1.0; drawAnimation.removedOnCompletion = NO; drawAnimation.fromValue = [NSNumber numberWithFloat:0.0f]; drawAnimation.toValue = [NSNumber numberWithFloat:1.0f]; drawAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]; […]

如何在iOS中的循环path上animation标签?

在我看来,我被卡在animationuiLabel。 其实我只是想让我的标签/文字在圆形path上animation。 我在互联网上search了很多,但找不到任何好的教程或例子,像我的问题。 我做了CAShapeLayer(圆)从0增加到最大值…. 同样,我希望我的标签/文本从圆形path的初始点开始移动,并在完成一个圆后返回到初始点。 希望我已经相当准确地解释了我的问题……如果有什么遗漏或不可理解的话。 请问我。 感谢预期。

在向后播放CABasicAnimation后,CALayer消失

我有一个CALayer,我已经添加了一个CABasicAnimation像这样: circle = CALayer() circle.frame = CGRect(x: 0, y: 0, width: 100, height: 100) circle.backgroundColor = UIColor.green().cgColor circle.cornerRadius = 50 circle.speed = 0 view.layer.addSublayer(circle) animation = CABasicAnimation(keyPath: "position") animation.duration = 1 animation.fromValue = NSValue(cgPoint: CGPoint(x: 50, y: 50)) animation.toValue = NSValue(cgPoint: CGPoint(x: view.bounds.width / 2, y: view.bounds.height / 2)) animation.fillMode = kCAFillModeBoth animation.isRemovedOnCompletion = false […]