Animating the transition of a subview in Cocoa Touch
-
11-02-2021 - |
Question
I have a view with a subview in it. The subview will contain other views.
When the user clicks on the menu on the left side, the contents of the subview will be switched: the current view will be removed and a new one will be added.
I want to animate this with an effect similar to UIModalTransitionStyleFlipHorizontal. How can I do this, considering that it wont be a modal form (it wont cover the entire screen)?
Solution
self.currentView.userInteractionEnabled = NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];
[UIView setAnimationDelegate:self];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.currentView cache:YES];
[self.currentView removeFromSuperview];
[self.view addSubview:self.someOtherView];
[UIView commitAnimations];
self.view.userInteractionEnabled = YES;
self.currentView = self.someOtherView;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow