Animate UILabel text size increase and decrease - iphone

I want to apply animation on UILabel text. I write the code to increase font size in animation block but animation is not applied.
[UIView beginAnimations:nil context:nil/*contextPoint*/];
monthsOnBoard.font=[UIFont fontWithName:#"digital-7" size:150];
daysOnBoard.font=[UIFont fontWithName:#"digital-7" size:150];
hoursOnBoard.font=[UIFont fontWithName:#"digital-7" size:100];
minutesOnBoard.font=[UIFont fontWithName:#"digital-7" size:100];
secondsOnBoard.font=[UIFont fontWithName:#"digital-7" size:100];
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.5];
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView commitAnimations];

The font of a UIView is not an animatable property. You should use transforms instead.
[UIView beginAnimations:nil context:nil/*contextPoint*/];
monthsOnBoard.transform = CGAffineTransformMakeScale(2.0, 2.0); //increase the size by 2
//etc etc same procedure for the other labels.
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.5];
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView commitAnimations];
similarly, you can play with the values in CGAffineTransformMakeScale(x, y); - x is the horizontal scale constant and y is the vertical one. Enjoy!!

it may be help you
monthsOnBoard.transform = CGAffineTransformScale(monthsOnBoard.transform, 1, 1);
[UIView beginAnimations:nil context:nil/*contextPoint*/];
monthsOnBoard.transform = CGAffineTransformScale(monthsOnBoard.transform, 4, 4);
[UIView setAnimationDelegate:self];
[UIView setAnimationDelay:0.5];
[UIView setAnimationDuration:1];
[UIView setAnimationRepeatCount:4];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView commitAnimations];

Related

animation between two UITextviews

[baseview addSubview:textView1];
textView1.alpha = 0.0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:textView1 cache:YES];
textView1.alpha = 1.0;
[UIView commitAnimations];
[baseview addSubview:textView2];
textView2.alpha = 0.0;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:textView2 cache:YES];
textView2.alpha = 1.0;
[UIView commitAnimations];
How i can animate between these two textviews.
Thanks for help
This should work to hide the first text view and show the second one:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:textView1 cache:YES];
{
textView1.alpha = 0.0;
textView2.alpha = 1.0;
}
[UIView commitAnimations];
Maybe you have to set the parent view as animation view (e.g. self.view).

two UIView Animation on the same image

Well I would like to have two UIView animation on a same image in the same method like this :
-(void)likeThis{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
image.alpha=0;
[UIView commitAnimations];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
image.transform = CGAffineTransformScale(5,5);
[UIView commitAnimations];
}
But there is only one of these UIView Animation who work.I don't know why.I think there is another way to put two animation for the same image but I don't know how. sorry for my english I'm french :/
You can just put them in the same animation block:
-(void)likeThis
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
image.alpha=0;
image.transform = CGAffineTransformScale(image.transform,5,5);
[UIView commitAnimations];
}
Note that CGAffineTransformScale takes three arguments:
CGAffineTransformScale(image.transform, 5.0, 5.0)
See http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html#//apple_ref/doc/uid/TP30000946-CH1g-F16985
Or you could use CGAffineTransformMakeScale:
http://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html#//apple_ref/c/func/CGAffineTransformMakeScale
Do you want them to happen simultaneously, or one after the other? If the former just include them both between a single set of beginAnimations..commitAnimations calls

Animating a UIView To A CGPoint

I am wondering how I would go about animating a UIView's to a specific CGPoint. The following is what I have so far (which doesn't work in it's current state):
#define MOVE_ANIMATION_DURATION_SECONDS 2
NSValue *pointValue = [[NSValue valueWithCGPoint:point] retain];
[UIView beginAnimations:nil context:pointValue];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:MOVE_ANIMATION_DURATION_SECONDS];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView commitAnimations];
Try:
#define MOVE_ANIMATION_DURATION_SECONDS 2
[UIView beginAnimations:nil context:pointValue];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:MOVE_ANIMATION_DURATION_SECONDS];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
CGRect frame = myUIViewObject.frame;
frame.origin = point;
myUIViewObject.frame = frame;
[UIView commitAnimations];
After the begin, but before the commit, change the value on your UI View.
If you're targeting 10.5 or above, you can use Core Animation via the animator proxy added to NSView. Try
[[someView animator] setFrame: someNewFrame];

Flip between Image 1, 2, 3 instead of Image 1,3 (iPhone SDK)

I'm using some pretty standard code to flip 2 UIImageViews that are inside a small view.
(I'm amazed it worked!)
But what if I had THREE UIImageViews inside a small view... and wanted to flip between all 3?
I thought I could just cut/paste 2 copies of my code... but I guess not.
When I try to flip 1>2.. and then 2>3... it just flips once... going directly from 1>3.
What happened to 2????
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image1 removeFromSuperview];
[myView addSubview:image2];
[UIView commitAnimations];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image2 removeFromSuperview];
[myView addSubview:image3];
[UIView commitAnimations];
The animations are not chained together like this. Basically, they are doing both animations at the same time. What you want is to create a new method for the second flip that will be called after the first one is done:
- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)contextn {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image2 removeFromSuperview];
[myView addSubview:image3];
[UIView commitAnimations];
}
Then in your existing method, put this line:
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
like so:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[image1 removeFromSuperview];
[myView addSubview:image2];
[UIView commitAnimations];
For more info, check the apple docs
You could set a 0.5 second delay on the start of the second animation.
Also, you may want to check out keyframe animations to do more advanced stuff like this.
Jill,
In your second code block, do the following.
[UIView beginAnimations:nil context:NULL];
// This will cause your second animation block to wait 0.5 second, which will be
// enough time for the second one to kick in and do it's thing.
[UIView setAnimationDelay:0.5];
[UIView setAnimationDuration:0.5];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:myView cache:YES];
[image2 removeFromSuperview];
[myView addSubview:image3];
[UIView commitAnimations];

How to create a multistage UIImageView animation?

I'm trying to do a multistage animation, so that a UIImageView (1) fades in, (2) moves, (3) slide off the screen.
Only stage 1 seems to work. What am I doing wrong? Here's the code:
// FIRST PART - FADE IN
-(void)firstAnim
{
// 'sprite' is a UIImageView
[sprite setAlpha:0.1f];
[UIView beginAnimations:#"anim1" context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.25];
[UIView setAnimationDidStopSelector:#selector(secondAnim)];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[sprite setAlpha:1.0f];
[UIView commitAnimations];
}
// SECOND PART - MOVE
-(void)secondAnim
{
[UIView beginAnimations:#"anim2" context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDidStopSelector:#selector(thirdAnim)];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
sprite.frame = CGRectMake(170, 184, 20, 20);
[UIView commitAnimations];
}
// THIRD PART - SLIDE OFF SCREEN
-(void)thirdAnim
{
[UIView beginAnimations:#"anim3" context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
sprite.frame = CGRectMake(170, 420, 20, 20);
[UIView commitAnimations];
}
You need to add a call to set yourself as the animation delegate:
[UIView setAnimationDelegate:self];
It would be a good idea to unset yourself as the delegate (set to nil) in the last animation block.
The complete solution to your question is:
1) set the animation delegate
2) use the correct selector and method signature
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:.5];
[UIView setAnimationDelegate:self]; //set delegate!
[UIView setAnimationDidStopSelector:
#selector(secondAnim:finished:context:)];
-(void)secondAnim:(NSString *)animationID
finished:(NSNumber *)finished
context:(void *)context {
//animation #2
}