views:

86

answers:

2

Hello

I have read that I can use the animator object in any UIView to make an animation and this is included in Core Animation so I wrote

[[label animator] setFrame:someRect];

But it gave a warning that UILabel may not respond to -animator

Also I can find the method [label setWantsLayer:YES];

Would anyone help me please?

+2  A: 

-animator and -setWantsLayer: methods are from cocoa (OS X), not cocoa-touch (iOS). UIKit objects are backed with layers by default.

Vladimir
+1  A: 
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[self.containerView addSubview:myLabel];

CGRect destination = CGRectMake(5, 5, 100, 100); //for instance

[UIView beginAnimations:@"animationIdentifierString" context:nil];
myLabel.frame = destination;
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //that's the default, actually, but set whatever you want there.
[UIView commitAnimations];

I just typed this right in here, so beware of typos. But this is the idea. Wrap changes to UIView subclasses in a call to [UIView beginAnimations: context:] and [UIView commitAnimations], set some configurations on the animations inside there, and boom, you're animating.

There are other ways to do it, but for my money this is the simplest.

Way more detail in the UIView class reference at http://developer.apple.com/iphone/library/documentation/uikit/reference/UIView_Class/UIView/UIView.html

Dan Ray