0

I'm building an iPad app and want to switch one of my subviews for another by pressing a button. I've been reading the documentation and this guide:

View Controllers: How to switch between views programmatically?

But I keep getting errors and the animations doesn't really happen, the views just switch immediately.

I'll paste some code below for context. I have a main view which has in it a sub uiview. In the sub uiview, there is another view. I want to swap the other view with another.

self.settingsViewController = [[GHPSettingsViewController alloc] initWithNibName: @"GHPSettingsViewController" bundle: nil andParent: self];
  UIView *outerView = [self.containingView viewWithTag:0];


  [UIView beginAnimations:@"View Flip" context:nil];
  [UIView setAnimationDuration: 100.25f];
  [UIView setAnimationDuration: UIViewAnimationCurveEaseInOut];

  if (self.settingsViewController.view.superview == nil) {
    // Flip Out Old View
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.containingView cache:YES];
    [self.settingsViewController viewWillAppear: YES];


    [outerView removeFromSuperview];
    [self.containingView insertSubview: self.settingsViewController.view atIndex: 0];

    [self.settingsViewController viewDidAppear: YES];
  }
  [UIView commitAnimations];
Community
  • 1
  • 1
Programmer9000
  • 1,959
  • 3
  • 17
  • 27
  • Here are the errors: Oct 1 15:07:07 Erics-MacBook-Pro-4.local GreenHome[80451] : CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update. .... – Programmer9000 Oct 01 '13 at 22:16
  • see this question, can help: http://stackoverflow.com/questions/9524048/how-to-flip-an-individual-uiview-without-flipping-the-parent-view . Also, do not use `-beginAnimations`, use block ones instead – medvedNick Oct 01 '13 at 22:21
  • Interesting, I had already thought to create a container view, but it seems that what ended up helping fix things was using: [UIView transitionFromView:oldView toView:newView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:NULL]; instead of what i had. – Programmer9000 Oct 01 '13 at 22:33

0 Answers0