animation between two UITextviews - iphone

[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).

Related

Flip Right UIView1 to UIView2

I have two UIViews VW1 and VW2 in the same UIViewController.
I'm trying to flip to the right from VW1 to VW2 and using the following code that I don't know how and where to call the method?
-(void)FlipFromRight
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:uiView2 cache:YES];
[UIView commitAnimations];
}
Above code is not working for me.
You need to do :
if ([VW1 superview])
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:aTableBGView cache:NO];
[VW1 removeFromSuperview];
[mainView addSubview:VW2];
[mainView sendSubviewToBack:VW1];
}
else
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:aTableBGView cache:NO];
[[mainView viewWithTag:2001] removeFromSuperview]; // VW2's tag ID
[mainView addSubview: VW1];
[mainView sendSubviewToBack: VW2];
}
[UIView commitAnimations];
here add one uIButton like name "btnSwipe" on navigationbar or on the MainViewcontroller and after that just give the button title for example i.e "Left".
after that give the action event with this bellow method
-(IBAction)FlipFromRight:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
if ([btnSwipe.titleLabel.text isEqualToString:#"Left"])
{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:uiView1 cache:YES];
[btnDraw setTitle:#"Right" forState:UIControlStateNormal];
}
else{
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:uiView2 cache:YES];
[btnDraw setTitle:#"Left" forState:UIControlStateNormal];
}
[UIView commitAnimations];
}
here just give the IBAction from xib to btnSwipe and it will work
i hope this is useful to you..
:)

Animate UILabel text size increase and decrease

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];

how to flip two views at once?

i'm trying to flip two views in one screen with a single button click,i.e i want to have multiple animations at the same time(ex:iPhone music player where the button and view flips at the same time)
p.s-i don't want to animate views one after another,it should be done together
EDIT
this is the code i used,please help me out
[UIView beginAnimations:nil context:nil];
[UIView animateWithDuration:0.8 animations:^{
if (viewDisplay)
{
[fareView removeFromSuperview];
[containerView addSubview:mapView];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:containerView cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:buttonView cache:YES];
viewDisplay = FALSE;
swapLabel.text = #"Fare View";
[mapOrFare setImage:[UIImage imageNamed:#"original_icon.png"] forState:UIControlStateNormal];
}
else
{
[mapView removeFromSuperview];
[containerView addSubview:fareView];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:containerView cache:YES];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:buttonView cache:YES];
viewDisplay = TRUE;
swapLabel.text = #"Map View";
[mapOrFare setImage:[UIImage imageNamed:#"Map.png"] forState:UIControlStateNormal];
}
}];
[UIView commitAnimations];
Assuming that bgView1 and bgView2 are the views to be flipped, as below; you should just be able to put the animator code one after the other and it should all work out ok. See below for the example,
-(void)flipViews {
CGContextRef context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:bgView1 cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[bgView1 exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
context = UIGraphicsGetCurrentContext();
[UIView beginAnimations:nil context:context];
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:bgView2 cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelegate:self];
[bgView2 exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
[UIView commitAnimations];
}
Just use block animations, it should work with no issues.
[UIView animateWithDuration:myDuration
animations:^{
<animation 1 code>;
<animation 2 code>;
}];

how to execute multiple animations in a row?

-(ibaction)sometouched:(id)sender
{
[UIView beginAnimations:#"first one" context:nil];
[UIView setAnimationDuration:1.0];
[myview setFrame:CGRectMake(0,y,width.height.);
[UIView commitAnimations];
[UIView beginAnimations:#"second one" context:nil];
[UIView setAnimationDuration:1.0];
[myview setFrame:CGRectMake(x,0,width.height.);
[UIView commitAnimations];
}
This is just a demonstrate. What I want is the animation will take 2 parts. the first one moves the view down, and the second one moves it to the right. but what i've got is it quickly moves down and then moves correctly to the right.
what did i miss here?
You need to start the second animation from the animationDidStop delegate method.
-(ibaction)sometouched:(id)sender
{
[UIView beginAnimations:#"first one" context:nil];
[UIView setAnimationDuration:1.0];
[myview setFrame:CGRectMake(0,y,width.height.);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];
}
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
[UIView beginAnimations:#"second one" context:nil];
[UIView setAnimationDuration:1.0];
[myview setFrame:CGRectMake(x,0,width.height.);
[UIView setAnimationDelegate:nil];
[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
}