Frederick C. Lee
Frederick C. Lee

Reputation: 9503

Move CALayer leaves behind original 'after-image'

Environment: Xcode 5.0.2/iOS 7

Goal: to merely move a layer from point 'A' to point 'B'.
Problem: the 'move' acts like a 'copy'.

I've tried 2 move paradigms:
1) set the layer's position; and
2):

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"position"];
animation.fromValue = [layer valueForKey:@"position"];
animation.toValue = [NSValue valueWithCGPoint:point];
layer.position = point;
[layer addAnimation:animation forKey:@"position"];

Note: The CALayer @ destination is accessible and am able to remove it from its container layer.
The CALayer @ origin apparently is orphaned.

Question: what would cause this 'move' to act as a 'copy'?
Any remedy?

Weird Note: this code works correctly within a different UIViewController's view.

Upvotes: 0

Views: 148

Answers (1)

Frederick C. Lee
Frederick C. Lee

Reputation: 9503

The problem stemmed from setting up the CALayers within UIViewController`s
- (void)viewDidLayoutSubviews {} <-- don't setup CALayers here!

rather than the correct:
- (void)viewDidLoad {} <-- preferred spot.

Creating CALayers within viewdidLayoutSubviews{} causes any position change to COPY vs MOVE.
However, creating CALayers within viewDidLoad{} behaves correctly: any position change is a MOVE.

Seems like a bug to me.

Upvotes: 1

Related Questions