Tag: cabasicanimation

animation只改变其他属性的图层属性?

想象一下CAGradientLayer 。 对.startPoint和.endPoint进行animation制作非常简单。 现在想象一个浮动的spinLike ,它只是简单地将它们同时设置 。 {所以,不要有两个不同的animation,你可以简单地为spinLikeanimation。 所以像.. class CustomGradientLayer: CAGradientLayer { @objc var spinLike: CGFloat = 0 { didSet { startPoint = CGPoint( … ) endPoint = CGPoint( … ) setNeedsDisplay() } } } animationspinLike … class Test: UIView { … g = CustomGradientLayer() a = CABasicAnimation(keyPath: "spinLike") … g.add(a, forKey: nil) … 但。 […]

UIBezierPath + CAShapeLayer – animation圈起来填满

我正在尝试对CAShapeLayer的path进行animation处理,这样我就可以得到一个圆圈“填充”到特定数量的效果。 问题 它“起作用”,但不是我想的那么顺利,我想介绍一些缓解。 但是因为我分别为每个animation制作了一个animation,所以现在我不确定这是可能的。 所以我正在寻找可以解决这个问题的替代scheme! 视觉解释 开始 – 这里是我试图实现的animation的一些“框架”(见图像 – 从0%到25%的圆圈填充) 码 我创造了绿色的中风(外面): let ovalPath = UIBezierPath(ovalInRect: CGRectMake(20, 20, 240, 240)) let circleStrokeLayer = CAShapeLayer() circleStrokeLayer.path = ovalPath.CGPath circleStrokeLayer.lineWidth = 20 circleStrokeLayer.fillColor = UIColor.clearColor().CGColor circleStrokeLayer.strokeColor = colorGreen.CGColor containerView.layer.addSublayer(circleStrokeLayer) 我创build了填充形状(内部)的初始path: let filledPathStart = UIBezierPath(arcCenter: CGPoint(x: 140, y: 140), radius: 120, startAngle: startAngle, endAngle: Math().percentToRadians(0), clockwise: true) […]

如何在UIViewanimation过程中animationUIView图层的子图层?

在视图的UIViewanimation中,通过在[UIView animateWithDuration:delay:options:animations:completion:]的options参数中包含UIViewAnimationOptionLayoutSubviews ,可以为其子视图设置[UIView animateWithDuration:delay:options:animations:completion:] 。 然而,当我们不是某个视图的背景层的时候,我找不到一个方法来为它的子层设置animation。 他们只是跳到适当的位置,以配合视图的新界限。 由于我正在使用图层而不是视图,看起来像我不得不使用核心animation而不是UIViewanimation,但我不知道如何(和何时)做到这一点,使图层animation将匹配视图animation。 这是我的基本问题。 如果你想知道我想要完成的具体事情,请阅读更多内容。 我已经创build了一个带有虚线边框的视图,在视图的图层中添加了一个CAShapeLayer(参见这个stackoverflow问题: UIView周围的虚线边框 )。 我调整了CAShapeLayer的path以匹配layoutSubviews视图的边界。 这个工作,但有一个化妆品的问题:当视图的边界animation在一个UIViewanimation(如在旋转期间),虚线边框跳转到视图的新边界,而不是平滑的animation,因为视图animation的边界。 也就是说,当视图animation时,虚线边框的右侧和底部不分别保持与视图的右侧和底部部分相邻。 我怎样才能从CAShapeLayer的虚线边界animation的边界animation的视图旁边? 我到目前为止所做的是将一个CABasicAnimation附加到CAShapeLayer上: – (void)layoutSubviews { [super layoutSubviews]; self.borderLayer.path = [UIBezierPath bezierPathWithRect:self.bounds].CGPath; self.borderLayer.frame = self.bounds; CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"path"]; [self.borderLayer addAnimation:pathAnimation forKey:nil]; } 这确实会使虚线边框生成animation,但它没有正确的计时function和animation持续时间以匹配视图animation。 另外,有时候,我们不希望虚线边框动起来,就像当视图第一次布局时,边框不应该从一些旧pathanimation到新的正确path; 它应该只是出现。

如何使CABasicAnimation后的UI对象响应

我在尝试find一种方法来让我的UI对象(UISegmentedControl)在CABasicAnimation幻灯片放入和popup后触摸响应。 我怎么能把这个关掉? 移动后,我知道UI对象在演示树中。 但是我真的很喜欢CABasicAnimation提供的setTimingFunction特性,而我不能使用UIViewanimation获得如此平滑的反弹。 animation的示例GIF(循环): 我在viewDidLoad中使用的代码 CABasicAnimation *startAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"]; [startAnimation setFromValue:[NSNumber numberWithFloat:0]]; [startAnimation setToValue:[NSNumber numberWithFloat:slidingUpValue]]; [startAnimation setDuration:1.0]; startAnimation.fillMode = kCAFillModeForwards; startAnimation.removedOnCompletion = NO; [startAnimation setTimingFunction:[CAMediaTimingFunction functionWithControlPoints:0.0 :0.0 :0.3 :1.8]]; [[gameTypeControl layer] addAnimation:startAnimation forKey:nil];

我如何同时animationUIImageView的图像和UIImageView本身?

标题可能不是那么清楚,但我想要做的是让UIImageView显示一系列图像(有点像GIF),我通过设置animationImages到一个图像数组,然后调用[imageView startAnimating]; 。 这工作正常。 我也有移动UIImageView的CABasicAnimation的代码,这个animation代码也可以正常工作。 但是,当我尝试为UIImageView的图像设置animation并尝试移动UIImageView时,UIImageView的图像停止animation。 有没有解决方法? 这里是我的animationUIImageView的内容的代码: self.playerSprite = [[UIImageView alloc] initWithImage:[self.player.animationImages objectAtIndex:0]]; [self.playerSprite setFrame:CGRectMake(self.center.x, self.center.y, self.tileSet.constants.TILE_WIDTH, self.tileSet.constants.TILE_HEIGHT)]; self.playerSprite.animationImages = self.player.animationImages; self.playerSprite.animationDuration = self.tileSet.constants.animationDuration; self.playerSprite.animationRepeatCount = 0; //Makes it repeat indefinitely 这里是我用CABasicAnimationanimationUIImageView的编码: float playerSpriteX = self.playerSprite.center.x; float playerSpriteY = self.playerSprite.center.y; CABasicAnimation *moveAnimation = [CABasicAnimation animation]; moveAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(playerSpriteX + TILE_WIDTH, playerSpriteY)]; [moveAnimation setDelegate:self]; […]

iOS:完整的360度旋转使用块,而不是CABasicAnimation

这应该是非常简单的事情,但我没有成功地使用块来实现这个function。 这里有一些问题和答案,但是我发现所有这些都是通过使用CABasicAnimation而不是UIView基于块的animation来解决的,而这正是我所追求的。 下面的代码不起作用(基于块),没有animation: CGAffineTransform spin = CGAffineTransformRotate(spiningView.transform, DEGREES_RADIANS(360)); CATransform3D identity = CATransform3DIdentity; CATransform3D spin2 = CATransform3DRotate(identity, DEGREES_RADIANS(360), 0.0f, 0.0f, 1.0f); [UIView animateWithDuration:3.0f delay:0.0f options:UIViewAnimationOptionCurveLinear animations:^ { spiningView.transform = spin; //spiningView.layer.transform = spin2; //Have also tried the above, doesn't work either. } completion:^(BOOL finished) { spiningView.transform = spin; //spiningView.layer.transform = spin2; }]; 根据我的理解,当我们每次使用基于块的时候,都不会发生animation,当UIViewAnimation Block“看到”开始值和最终值相同时。 公平的说,把它设置成360度就意味着对象停留在原来的位置。 但它必须是一种使用基于块的animation来制作这个animation的方法,因为下面的CABasicAnimation可以完美地工作: […]

iOS的animation/变形形状从圆形到方形

我试图把一个圆圈变成一个正方形,反之亦然,我快到了。 然而它并不像预期的那样animation。 我希望广场的所有angular落都能同时进行animation/变形,但我得到的是以下内容: 我使用CAShapeLayer和CABasicAnimation为了animation形状属性。 以下是我如何创build圆path: – (UIBezierPath *)circlePathWithCenter:(CGPoint)center radius:(CGFloat)radius { UIBezierPath *circlePath = [UIBezierPath bezierPath]; [circlePath addArcWithCenter:center radius:radius startAngle:0 endAngle:M_PI/2 clockwise:YES]; [circlePath addArcWithCenter:center radius:radius startAngle:M_PI/2 endAngle:M_PI clockwise:YES]; [circlePath addArcWithCenter:center radius:radius startAngle:M_PI endAngle:3*M_PI/2 clockwise:YES]; [circlePath addArcWithCenter:center radius:radius startAngle:3*M_PI/2 endAngle:M_PI clockwise:YES]; [circlePath closePath]; return circlePath; } 这是方形path: – (UIBezierPath *)squarePathWithCenter:(CGPoint)center size:(CGFloat)size { CGFloat startX = center.x-size/2; CGFloat […]

圆弧段的笔画animation以完整笔画结束

我正在试图创build一个圆的一部分的外观animation。 为了存档,我使用了安静的CABasicAnimations。 animation从上面开始,很好地移动到整个圈子的三分之一。 但是当animation结束时,圈子正在被完全画出。 我怎样才能防止呢? 这是我的自定义UIView的源代码: – (void)drawRect:(CGRect)rect { int radius = 100; int strokeWidth = 10; CGColorRef color = [UIColor redColor].CGColor; int timeInSeconds = 5; CGFloat startAngle = 0; CGFloat endAngle = 0.33; CAShapeLayer *circle = [CAShapeLayer layer]; circle.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 2.0*radius, 2.0*radius) cornerRadius:radius].CGPath; circle.position = CGPointMake(CGRectGetMidX(self.frame)-radius, CGRectGetMidY(self.frame)-radius); circle.fillColor = [UIColor clearColor].CGColor; […]

CABasicAnimation旋转返回到原来的位置

我旋转CALayer使用CABasicAnimation,并正常工作。 问题是,当我尝试旋转同一图层时,它将在旋转之前返回到其原始位置。 我预期的结果是,下一轮,它应该从结束的地方开始。 这是我的代码: CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; animation.fromValue = 0; animation.toValue = [NSNumber numberWithFloat:3.0]; animation.duration = 3.0; animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; animation.removedOnCompletion = NO; animation.fillMode = kCAFillModeForwards; animation.autoreverses = NO; [calayer addAnimation:animation forKey:@"rotate"]; 我的代码有什么缺失? 谢谢