Drawing and animating with UIView or CALayer?

I am trying to implement a graph that draws uiview. There are 3 UIViews for animating the left / right slide. The problem is that I cannot cancel the UIView animation. So I replaced UIViews with CALayer. Now the question is, is CALayer suitable for this? Is it ok to draw on CALayer like this? And why is CALayer so slow when I manage the properties of the frame.

CGRect frame = curve.frame;
frame.origin.x -= diffX;
[curve setFrame:frame];

Is there an alternative?

PS I'm a German guy. Sorry for mistakes.


I got the animation with CATransaction, but now I will animate the x movement with CABasicAnimation. To avoid problems, expect the position of the layer to return to the previous x.

CABasicAnimation *theAnimation; 
theAnimation = [CABasicAnimation animationWithKeyPath:@"position"]; 
theAnimation.delegate = self;
theAnimation.duration = 1.0;
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
CGPoint position = [[curves objectAtIndex:i]position];
position.x = [[curves objectAtIndex:i]position].x - diffX;
[theAnimation setToValue:[NSValue valueWithCGPoint:position]];
[[curves objectAtIndex:i] addAnimation:theAnimation forKey:[NSString stringWithFormat: @"translate.x.%d", index]];

(, xStart = 100, xEnd = 200), , x (, x = 100). ? , ? removeOnComplete, .

.

+3
2

, "", CALayer " ". , . :

[CATransaction begin];
[CATransaction setValue: (id) kCFBooleanTrue forKey: kCATransactionDisableActions];
[curve setFrame:frame];
[CATransaction commit];

CALayer. UIViews , .

+1

, "", , .

Animation: theAnimation, " " keyPath, .

, , , (0,0) (500 500), CoreAnimation . TheAnimation , .

0

Source: https://habr.com/ru/post/1740295/


All Articles