uiviewcontrollerios7uimodaltransitionstyle

UIViewController Transition Goes To Black


I have the code below to transition from one UIViewController to a UIViewController with a Storyboard.

#import "How_FarViewController.h"

MainViewController *screen = [[MainViewController alloc] initWithNibName:nil bundle:nil];
screen.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:screen animated:YES];

But when I go to press it it does a flip animation and just shows black. What's my problem??

Thanks, SebOH


Solution

  • You are using a storyboard, so go back to your storyboard. I assume you have the MainViewController and the How_FarViewController on the the storyboard. If that is the case you need to add a segue from the control to the view controller that you wish to flip over onto the parent view controller.

    To do this, control-click the control and drag to the view controller that you want to be displayed and release. A small dialog will be displayed asking you what kind of segue you want: select Modal. This will create a modal segue which is displayed as an arrow with a circle in it that displays the type.

    To ensure that you get "flip horizontal" transition, ensure the segue "arrow" is selected and go the the Attributes Inspector. In the Attributes Inspector panel you'll see a Transition selection, click the drop down and select Flip Horizontal.

    Final delete the code you have above compile and run. The storyboard manages all of the rest. But remember to add a button to your modal view controller to dismiss the modal view controller or you'll be stuck in the modal once you call it.