Subview fade in and fade out help - iphone

I am having a problem fading out my subview. I have no trouble fading the view in but fading out ..just drops the view.
-(void)flipToReview {
ReviewViewController *reviewVariable = [[ReviewViewController alloc] initWithNibName:#"ReviewViewController" bundle:nil];
[self setReviewViewController:reviewVariable];
self.ReviewViewController.view.alpha =0;
[UIView beginAnimations:#"flipview" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES];
[reviewVariable release];
[self.window addSubview:self.ReviewViewController.view];
self.ReviewViewController.view.alpha =1;
[UIView commitAnimations];
}
-(void)flipBackFromReview {
// self.ReviewViewController.view.alpha = 1;
[UIView beginAnimations:#"trip" context:nil];
[UIView setAnimationDuration:0.3];
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:NO];
self.ReviewViewController.view.alpha = 0;
[self.ReviewViewController.view removeFromSuperview];
[UIView commitAnimations];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
[self.ReviewViewController.view setHidden:1];
NSLog(#"remove subview");
}

Try the following:
[UIView animateWithDuration:3.0 delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{ ReviewViewController.view.alpha = 0.0;}
completion:^(BOOL fin) {
if (fin) [ReviewViewController.view removeFromSuperview];
}];

You need to move:
[self.ReviewViewController.view removeFromSuperview];
That cannot be done "over time" in an animation. What you want to do is move that to a selector and use setAnimationDelegate and setAnimationDidStopSelector. Put the following in your animation block:
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(finshedFadeOut)];
Then make the following method:
- (void)finshedFadeOut {
[self.ReviewViewController.view removeFromSuperview];
}

I had this issue as well, the way I got around it was changing the alpha to 0, instead of just removing the view. That can be animated.

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

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

Looking for a within app transition (revolving screen effect)

I want a transition within my app that is like the mystery revolving wall from old scooby doo cartoons. I want the screen to revolve when switching views. Anyone point me in the right direction for the possibility of accomplishing this?
Or this, which uses far less ink:
UIView *bookCaseView; // this is the container... the haunted wall
UIView *booksView; // just an ordinary set of books, right?
UIView *spookyBackside; // ruh-roh, raggy!
[UIView transitionWithView:containerView
duration:0.2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[booksView removeFromSuperview];
[bookCaseView addSubview:spookyBackside]; }
completion:NULL];
I think this is what you are looking for:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
//optional if you want to do something after the animation
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(myAnimationDidFinish:finished:context:)];
//
[view2 setFrame:CGRectMake(0, 0, view2.frame.size.width, view2.frame.size.height)];
[view1 addSubview:view2];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:view1 cache:YES];
[UIView commitAnimations];
And to flip back:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
//optional if you want to do something after the animation
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(myOtherAnimationDidFinish:finished:context:)];
//
[view2 removeFromSuperview];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:view1 cache:YES];
[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>;
}];

Blink hidden and using blocks

I have the method:
- (void)blinkView:(UIView *)view
{
view.layer.opacity = 0.0f;
view.hidden = NO;
[UIView beginAnimations:#"Blinking" context:nil];
[UIView setAnimationRepeatCount:1.0];
[UIView setAnimationDuration:0.6f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
view.layer.opacity = 1.0f;
[UIView commitAnimations];
}
How can i write this code with blocks, and how i must implement method with reverse effect (hide uiview with blink) ?
[UIView transitionWithView: view
duration:0.6f
options:UIViewAnimationOptionCurveEaseInOut
animations:^{ view.layer.opacity = 1.0f; }
completion:NULL];
or
[UIView transitionWithView: view
duration:0.6f
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{ view.layer.opacity = 1.0f; }
completion:NULL];
You can set the repeat count by recursively calling the animation block (see here).
Hope it will help you.
You can use UIView's setAnimationDelegate: and setAnimationDidStopSelector:
[UIView beginAnimations:#"Blinking" context:nil];
[UIView setAnimationRepeatCount:1.0];
[UIView setAnimationDuration:0.6f];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
view.layer.opacity = 1.0f;
[UIView commitAnimations];
- (void) animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
// add your final code here : you can give new animation effect here.
}
Or try animateWithDuration (available only in iOS 4 or later)
[UIView animateWithDuration:0.6f
animations:^{
view.layer.opacity = 1.0f;
}
completion:^(BOOL completed){
// add your final code here : you can give new animation effect here.
}
];