2

I have come across the following thread which sorted out part of my problem. (I tried to raise my question there but it seems its better putting it in a new thread).

Does iPhone OS support implicit animation?

The other part of my problem is the following

The approach recommended by justinkmunger in the thread above works fine for me:

CALayer *labelLayer = self.label.layer;
labelLayer.delegate = self;
layer.position = CGPointMake(labelLayer.position.x, labelLayer.position.y + 50);

However, I have two questions here:

1) how would i apply this approach to a CALayer object that is a sublayer of a UIView layer object, like in the following:

CALayer* l = [CALayer layer];
l.frame = CGRectMake(0, 0, 200, 350);
layer.opacity = 0;
[self.view.layer addSublayer:l];

l.delegate = self;
[CATransaction setAnimationDuration:5];
1.opacity = 1;    // DOES NOT ANIMATE!! Event if i add: self.view.layer.delegate = self;

2) Why this approach is not applicable to the layer in my UIViewController's view?

CALayer *layer = self.view.layer;
layer.delegate = self;
layer.opacity = 0;
[CATransaction setAnimationDuration:5];
layer.opacity = 1;   // DOES NOT ANIMATE!!
Many thanks AF

Hope someone can help Cheers AF

Community
  • 1
  • 1
Abolfoooud
  • 2,663
  • 2
  • 27
  • 27

2 Answers2

2

After doing some more search i came across the following on Core Animation Programming Guide:

Important: When modifying layer properties from threads that don’t have a runloop, you must use explicit transactions.

I am trying to activate the animation of the layers from Button clicks. Not sure if those are triggered on a separate thread and causing the fail of animating. Just thought of sharing this finding in case some else finds it useful.

Abolfoooud
  • 2,663
  • 2
  • 27
  • 27
-2

don't you need [CATransaction begin]; and [CATransaction commit];

RolandasR
  • 3,030
  • 2
  • 25
  • 26