Tag Archives: iPhone

Basic CA (Core Animation) for your iPhone

31 May

UPDATE: New post can be found here. Below’s content is incorrect.

After struggling for several hours trying to a get a simple implicit basic animation working on the iPhone I finally managed. What I tried to do is simply scale a view for my fade out animation (basically what your app does  when it quits).

I firstly tried to read in to the documentation provided by Apple, while this documentation certainly provides good content and in dept information about CA but what it truly lacks is decent samples; kinda disappointing. What Apple basically says about implicit animations is that when you do the following:

CALayer *layer = self.view.layer;
layer.position.x = 20;

According to Apple this works. Well I beg the difference. Maybe I’m doing something wrong (although I’ve been checking forums and this seems a pretty common error/problem) or Apple just screws us over! Go a head and try it out if you like, you probably will just see an update of the position of your view, but no animation. What our view’s layer is missing is a delegate so to speak. According to Apple’s documentation the delegate of the layer is the view it belongs to. Well maybe, but I’m sure that ain’t working! What you have to do is set the delegate of the view’s layer to the controller the view belongs to, makes sense?

Here’s the code to transform a controller’s view making it fade out like when you quit the app.

CALayer *layer = self.view.layer;
layer.delegate = self;
layer.opacity = 0.1;
layer.transform = CATransform3DMakeScale(.001, .001, 1.0);

Hope that helps anyone diving in to CoreAnimation like me :)

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: