-
Notifications
You must be signed in to change notification settings - Fork 111
Containers modal storyboard example
Samuel Défago edited this page Nov 28, 2014
·
3 revisions
In this example, we implement the same modal-like behavior as in another example, this time using storyboards.
- Create a new Xcode project with storyboards (use the Single View Application template) and add CoconutKit
- Remove the
ViewController
class automatically added by the template, as well as the associated object in the storyboard - Drop a view controller onto the storyboard (this defines an initial view controller for the storyboard) and set its class to
HLSStackController
. To set the stack root view controller, drop another view controller onto the storyboard, and draw a segue from the stack controller to the second view controller, setting the segue class toHLSStackPushSegue
and its identifier tohls_root
:
```objective-c
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"push_modal"]) {
HLSStackPushSegue *stackPushSegue = (HLSStackPushSegue *)segue;
stackPushSegue.transitionClass = [HLSTransitionFadeIn class];
}
}
```
-
Add a
ModalViewController
class to your project (you should subclassHLSViewController
, as said previously), and use it as class property of the third view controller your dropped onto the storyboard. Bind the close button to the following action:- (IBAction)close:(id)sender { [self.stackController popViewControllerAnimated:YES]; }
Since iOS 6, popping view controllers can also be achieved using segue unwinding.
- Build and run the application. Try to display and hide the modal and to rotate the device. If your autoresizing masks were set up properly, the views should behave properly when rotating. Congratulations! You have successfully used
HLSStackController
in a storyboard!