Here's my current screen:
This screen consists of a UIViewController with programatically created buttons Current Bookings
and Old Bookings
. I have the logic on how to make the tapped active by adding a UIView as a subview to the UIButton.
All the space below the buttons is occupied by a container view where I want to add different UIViewControllers based on which button is active.
Initially, I do this to load one of the view controllers when the parent view appears,
DRMCurrentBookingsViewController *cbvc = [self.storyboard instantiateViewControllerWithIdentifier:@"CurrentBookingsController"];
[self addChildViewController:cbvc];
// 64 is the height of the navigation bar
cbvc.view.frame = CGRectMake(0, 64+50, self.view.bounds.size.width, self.view.bounds.size.height-50);
[container addSubview:cbvc.view];
[cbvc didMoveToParentViewController:self];
Then, when the user taps on a different button, I use this code to switch the views.
DRMCurrentBookingsViewController *newController = [self.storyboard instantiateViewControllerWithIdentifier:@"CurrentBookingsController"];
DRMOldBookingsViewController *oldController = [self.childViewControllers objectAtIndex:0];
[oldController willMoveToParentViewController:nil];
[self addChildViewController:newController];
[self transitionFromViewController:oldController
toViewController:newController
duration:0.5
options:UIViewAnimationOptionTransitionNone
animations:^{
// no further animations required
newController.view.frame = oldController.view.frame;
}
completion:^(BOOL finished) {
[oldController removeFromParentViewController];
[newController didMoveToParentViewController:self];
}];
But, I want the child views to slide from left-right or right-left depending on which button is tapped and I do not want to select the pre-defined UIViewAnimationOption
. I do not even wish to fade in the views. The views have to slide from one end to the other.
How can I achieve this?
Thanks for any help.