Flip Animation

Discussion in 'iOS Programming' started by computerartist, Sep 8, 2010.

  1. computerartist macrumors newbie

    Joined:
    Sep 4, 2010
    #1
    I am trying to use a "Flip" transition/animation. On both sides I want to have 2 separate UITables.


    The following code that I am trying to do this with works fine, but it obviously "Flips" with the same view:


    Code:
    	CGContextRef context = UIGraphicsGetCurrentContext();
    	[UIView beginAnimations:nil context:context];
    	[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    	[UIView setAnimationDuration:1.0];
    	[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    	[UIView commitAnimations];
    

    I don't know where I would include the second UITable for the backside?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Have you tried looking at how the Utility Application template does it or even the ViewTransitions sample app?
     
  3. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #3
    Even simpler...use two view controllers, one for the front, one for the back (they would both be UITableViewController subclasses in your case).

    Present the back as a modal view controller and set the modal transition style of the back view controller to UIModalTransitionStyleFlipHorizontal. No animation blocks, no view swapping, both views managed by their own controller so your code is cleaner, simple.
     
  4. computerartist thread starter macrumors newbie

    Joined:
    Sep 4, 2010
    #4
    I understand all of that, but I don't know where to start touse two view controllers,:


    "one for the front, one for the back"


    ???
     
  5. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #5
  6. computerartist thread starter macrumors newbie

    Joined:
    Sep 4, 2010
  7. computerartist thread starter macrumors newbie

    Joined:
    Sep 4, 2010
    #7
    Read through it and still don't know what i am doing wrong.
     
  8. computerartist thread starter macrumors newbie

    Joined:
    Sep 4, 2010
    #8
    I have the following code now that is working.

    The problem I am running into now though is that the UINavigationController is flipping too:


    Code:
    	DetailViewControllerLatestElectionPolls *controller = [[DetailViewControllerLatestElectionPolls alloc] initWithNibName:@"DetailView" bundle:nil];
    	UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
    	[controller release];
    	navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    	[self presentModalViewController:navController animated:YES];
    	[navController release];
    
     
  9. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #9
    My solution isn't going to work for you if you are using a navigation controller and don't want it to flip, something you failed to mention in your first post.
     
  10. computerartist thread starter macrumors newbie

    Joined:
    Sep 4, 2010
    #10
    I didnt know it would make a difference.

    So I need to use an animation block? That is good to know because I still can't figure this out.

    Any suggestions of what I am doing wrong?

    Code:
    CGContextRef context = UIGraphicsGetCurrentContext();
    [UIView beginAnimations:nil context:context];
    [UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.view cache:YES];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:1.0];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    [UIView commitAnimations];
    
     
  11. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #11
    What is going wrong exactly? What does the rest of your code look like? Can you post the relevant class and header?
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    Does the following line work, without the animation?:
    Code:
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
     
  13. computerartist thread starter macrumors newbie

    Joined:
    Sep 4, 2010
    #13
    Yes, but what I am having a problem with is:

    What I am trying to do is to make the Application Delegate Navigation Controller the Navigation Controller for a programmatically inserted tableView (only the view, not the view with navigation controller... if this is possible.



    What I was hoping for is that I could do something like the following:


    Code:
    navController = tableViewAppDelegate.navigationController;
    


    Code:
    	tableViewAppDelegate = (TableViewAppDelegate *) [[UIApplication sharedApplication] delegate];
    
    	DetailViewControllerSenateNoTossUp *cnewTableViewFrameController = [[DetailViewControllerSenateNoTossUp alloc] initWithNibName:@"DetailView" bundle:nil];
    	UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:newTableViewFrameController];
    	
    
    
    	CGRect newTableViewFrame;
    	newTableViewFrame.origin.x = 0; 
    	newTableViewFrame.origin.y = 0;
    	newTableViewFrame.size.height = 200;
    	newTableViewFrame.size.width = 280;
    	
    	UIView *newTableView = [[UIView alloc] initWithFrame: newTableViewFrame];
    	newTableView = newTableViewFrameController.view;
    	
    	[self.view addSubview:newTableViewFrameController.view];
    
     

Share This Page