Reputation: 5722
I have a UITableView
controller displaying static tableview
. I have to update the project providing a secondary mode where this tableview
is supposed to flip and to show different data. My approach would be to put all the static cells of both modes in one big static tableview
, to perform a flip and to hide the cell which are not required at that specific moment. The flip should be performed only on the tableviewcontrollerview
,so not affecting the navigationbar
or the main tabbar
. The code I've been trying to use so far for realising this simple magic trick is:
// Transition using a page flip.
[UIView transitionFromView:self.tableview
toView:self.tableview
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:^(BOOL finished) {
if (finished) {
/* HIDE NOT REQUIRED CELL */
}
}];
Unfortunately the result is a black screen. Any idea how to fix it?
Upvotes: 4
Views: 3175
Reputation: 3399
Try using the below code instead:
[UIView transitionWithView:self.tableView
duration:0.7
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
/* any other animation you want */
} completion:^(BOOL finished) {
/* hide/show the required cells*/
}];
Upvotes: 8
Reputation: 1106
I've accomplished this using a slightly different technique. Perhaps it's useful for you. the basic structure is that there is a MainContainerView and inside that is a MapView (in your case a table view). When I do the flip animation I grab the view of a separate view controller (list view) and add it as a subview to the MainContainerView and remove the MapView from the subview. When I want to flip back I do the opposite.
-(void)listViewButtonHandler:(id)sender
{
if (_isMap) { //transition to view 2
self.listViewController.view.frame = self.mainContainerView.bounds; //grab the view of a separate VC
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.mainContainerView
cache:YES];
[self.mapContainerView removeFromSuperview];
[self.mainContainerView addSubview:self.listViewController.view];
[UIView commitAnimations];
self.navigationItem.leftBarButtonItem = [UIBarButtonItem barItemWithImage:[UIImage imageNamed:@"mapButton"] target:self action:@selector(listViewButtonHandler:)]; //change the button to another title
_isMap = NO;
} else {
//transition to view 1
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.mainContainerView
cache:YES];
[self.listViewController.view removeFromSuperview];
[self.mainContainerView addSubview:self.mapContainerView];
[UIView commitAnimations];
_isMap = YES;
self.navigationItem.leftBarButtonItem = [UIBarButtonItem barItemWithImage:[UIImage imageNamed:@"actualListButton"] target:self action:@selector(listViewButtonHandler:)]; //change the button back
}
}
I hope this is helpful and that it can apply to your situation!
Upvotes: 1
Reputation: 6065
I think the main problem is, that views can have max one superview. Which means a view can not be in two places in the same time. I would try capture the view as image and add it on its superview just before animation and remove the real tableview from its superview. And then you can animate between two different views (image view and table view). In completion block just remove the image view.
How to capture the view :How to capture current view screenshot and reuse in code? (iPhone SDK)
Upvotes: 1