0

I am looking at implementing some custom IOS7 Transitions. For example these here.

When a button is pressed in this example the following is run:

-(void)showNewController:(id)sender{
    
    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
    UIViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"PresentedViewController"];

    if(sender == self.button1){
        self.animationController = [[ZoomAnimationController alloc] init];
    }else{
        self.animationController = [[DropAnimationController alloc] init];
    }
    
    controller.transitioningDelegate  = self;
    [self presentViewController:controller animated:YES completion:nil];
}

Question
I am trying to understand the correct place to pass information to the new UIViewController. As an example lets say I am trying to pass a UIImage to the new (to be) presented view controller.

Typically I would complete this in the prepareForSegue method, but as this is not a segue what would be the correct way to pass the data.

I could simply add in as an example the following:

controller.passingImage = self.imageToPass;

Would this be the correct process to follow when working with custom transitions in IOS7?

Community
  • 1
  • 1
StuartM
  • 6,743
  • 18
  • 84
  • 160
  • 1
    If you want to be able to use the passed variable in ViewDidLoad:, pass it before you present. Otherwise, its better to pass it in the completion block so the UI is smoother. The actual way you are passing controller.passingImage = self.imageToPass; seems fine – Jack Jan 13 '14 at 23:12
  • @JackWu - thanks for confirming – StuartM Jan 14 '14 at 10:45

1 Answers1

1

The way you setup view controllers doesn't change when you use the new custom animated transitions in iOS 7. So you would still setup the view controller (including setting the transitioningDelegate) in prepareForSegue if you're using storyboards.

See the following sample code for examples of custom animated transitions using storyboards. It's an implementation of the sample code for WWDC Session 218: Custom Transitions Using View Controllers. Look at SOLViewController.m to get started.

https://github.com/soleares/SOLPresentingFun

Jesse
  • 1,667
  • 12
  • 16
  • Thanks for this. when you create a segue from one controller to the next it asks for Push/Model/custom I selected custom originally and my transition was not run. By changing it back to use presentViewController instead of perforSegueWith... it worked as expected? – StuartM Jan 14 '14 at 10:46
  • You would want to use a push or modal segue. If you use a custom segue then you need to implement a custom segue which isn't what you want. Modal is equivalent to calling presentViewController:animated: and Push is equivalent to calling pushViewController:animated. – Jesse Jan 14 '14 at 11:18
  • FYI push does not work it just does a push segue as normal, but modal does do my custom transition, not sure if that is normal? – StuartM Jan 14 '14 at 17:20
  • For push you'll need to set self.navigationController.delegate and implement the UINavigationControllerDelegate method that returns the animationController. You can see this in my example code in SOLViewController.m. If you click Options and toggle 'Do Push Transitions' you can switch between modal and push. – Jesse Jan 14 '14 at 17:36
  • @Jesse Is this a dummies guide to https://github.com/soleares/SOLPresentingFun anywhere? – maxisme May 30 '14 at 14:35
  • 1
    @Maximilian check out the video for 2013 WWDC Session 218: Custom Transitions Using View Controllers. The project was based on this session. – Jesse May 31 '14 at 22:15
  • @Jesse Also have you seen the stack exchange app? Do you know how to do that type of view controller transition? It seems to happen in a lot of apps I have seen? – maxisme Jun 01 '14 at 14:29