RemoveFromSuperview with animation and presentation controls

I did a bit of work around this, but actually did not answer my question (not even that: Is it possible to remove FromSuperview with animation? ).

Basically, my application starts with a welcome screen where the user clicks “Register”, then goes to the sign, and then goes to the tab bar view, which is the actual application.

As I did this, I wrote my own class - TabBarController, which sets all the tabs and their respective view controllers. Now, when the user clicks "Register", I call removeFromSuperview and present the tab.

I am trying to find a way to animate the transition from a character on a page to a tab bar. I tried some of the suggested solutions here, but no one seems to be doing this work. Here is my code in the signin.m controller. I am looking to animate the current view (ideally, not only attenuation, but also cooler things like flips, etc.).

//when done signing in --> go to the tab bar view -(IBAction)done:(id)sender { TabBarController *tabController = [[TabBarController alloc] init]; [UIView beginAnimations:@"removeWithEffect" context:nil]; [UIView setAnimationDuration:4.0]; self.parentViewController.view.frame = CGRectMake(0,0,320,480); self.parentViewController.view.alpha = 1.0f; [UIView commitAnimations]; [self.parentViewController.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:2.5f]; [self presentModalViewController:tabController animated:YES]; } 

Appreciate any help!

+4
source share
2 answers

This may not work like that. presentModalViewController displays a viewController in its own way. It will not replace the original viewController (self). Since you remove self.parentViewController.view from the view hierarchy, it cannot represent your tabController modally because you deleted yourself.

Anyway, I would recommend you another way to achieve the layout of the view: Create a tabBarViewController and add its view to rootView (self.window in the application delegate or whatever you are currently using). Then add your view of the entrance to the same point of view. Due to the hierarchy of views, the input view will be displayed above tabBar.view. And the done button should be implemented as follows: (I use block syntax for animation, as it should be)

 -(IBAction)done:(id)sender { [UIView animateWithDuration:1.0 animations:^{ self.view.frame = CGRectMake(0, 480, 320, 480); self.view.alpha = 0.0 } completion:^(BOOL finished){ [self.view removeFromSuperView]; } ]; } 

You can animate more things than just alpha, size, or position. Just watch the animation in the documentation . I think you will be interested in view.transform for transferring flip animations .;)

+11
source

Here's how you need to delete a view after it is animated.

 [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; [UIView setAnimationDelay:2.0]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationDelegate:myView]; [UIView setAnimationDidStopSelector:@selector(removeFromSuperview)]; [UIView commitAnimations]; 

Hope this helps. Happy coding.

+1
source

All Articles