Skip to content

Commit

Permalink
update readme.add pod spec
Browse files Browse the repository at this point in the history
  • Loading branch information
smolin_in committed Dec 31, 2013
1 parent 7dffeb0 commit 8850018
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 39 deletions.
37 changes: 37 additions & 0 deletions EmbeddedSwapping.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Pod::Spec.new do |s|
s.name = "EmbeddedSwapping"
s.version = "1.0"
s.summary = "Container view controller which manage multiple child view controllers using storyboards"
s.homepage = "https://github.com/mkutgt72/EmbeddedSwapping"
s.license = {
:type => 'MIT',
:text => <<-LICENSE
Copyright (c) 2012 Michael Luton
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
LICENSE
}
s.author = { "Michael Luton" => "https://github.com/mluton" }
s.source = { :git => "https://github.com/mkutgt72/EmbeddedSwapping.git", :tag => "1.0" }
s.source_files = ['EmptySegue.{h,m}',
'ContainerViewController.{h,m}']
s.ios.deployment_target = '5.0'
s.requires_arc = true
end
1 change: 1 addition & 0 deletions EmbeddedSwapping/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
static NSString* const secondControllerSegueIdentifier = @"embedSecond";

@interface ViewController ()

@property (nonatomic, weak) ContainerViewController *containerViewController;

- (IBAction)swapButtonPressed:(id)sender;
Expand Down
76 changes: 37 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,50 @@
Demonstration of how to make a custom container view controller manage multiple child view controllers using storyboards. This solution is heavily based on [Peregrin Planet's Container View Controllers in the Storyboard](http://orderoo.wordpress.com/2012/02/23/container-view-controllers-in-the-storyboard/).
Demonstration of how to make a custom container view controller manage multiple child view controllers using storyboards. This idea based on [mluton/EmbeddedSwapping](https://github.com/mluton/EmbeddedSwapping) code.

The child view controllers are connected to their container with a custom segue. The custom segue doesn't do anything but exists for the purpose of connecting things together in the storyboard. The custom container view controller manages the child view controllers in `prepareForSegue:sender`.

Usage example with custom animation:

```objective-c
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if (([segue.identifier isEqualToString:SegueIdentifierFirst]) && !self.firstViewController) {
self.firstViewController = segue.destinationViewController;
}
#import "ViewController.h"
#import "ContainerViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"

if (([segue.identifier isEqualToString:SegueIdentifierSecond]) && !self.secondViewController) {
self.secondViewController = segue.destinationViewController;
}
static NSString* const firstControllerSegueIdentifier = @"embedFirst";
static NSString* const secondControllerSegueIdentifier = @"embedSecond";

if ([segue.identifier isEqualToString:SegueIdentifierFirst]) {
if (self.childViewControllers.count > 0) {
[self swapFromViewController:[self.childViewControllers objectAtIndex:0] toViewController:self.firstViewController];
}
else {
[self addChildViewController:segue.destinationViewController];
UIView* destView = ((UIViewController *)segue.destinationViewController).view;
destView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
destView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:destView];
[segue.destinationViewController didMoveToParentViewController:self];
}
}
else if ([segue.identifier isEqualToString:SegueIdentifierSecond]) {
[self swapFromViewController:[self.childViewControllers objectAtIndex:0] toViewController:self.secondViewController];
}
}
@interface ViewController ()

@property (nonatomic, weak) ContainerViewController *containerViewController;

- (IBAction)swapButtonPressed:(id)sender;

- (void)swapFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController
{
toViewController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
toViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
@end

[fromViewController willMoveToParentViewController:nil];
[self addChildViewController:toViewController];
@implementation ViewController

[self transitionFromViewController:fromViewController toViewController:toViewController duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finished) {
[fromViewController removeFromParentViewController];
[toViewController didMoveToParentViewController:self];
self.transitionInProgress = NO;
}];
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"embedContainer"]) {
self.containerViewController = segue.destinationViewController;

self.containerViewController.animationBlock = ^void(UIViewController* container, UIViewController* fromViewController, UIViewController* toViewController) {
[container transitionFromViewController:fromViewController toViewController:toViewController duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finished) {
[fromViewController removeFromParentViewController];
[toViewController didMoveToParentViewController:self];
}];
};
}
}
```

See the [blog post](http://sandmoose.com/post/35714028270/storyboards-with-custom-container-view-controllers) for a more detailed description. Download the full project for the complete solution. Comments, Feedback, Suggestions: [Michael Luton](mailto:[email protected])
- (IBAction)swapButtonPressed:(id)sender {
if ([self.containerViewController.currentController isKindOfClass:[FirstViewController class]]) {
[self.containerViewController performSegueWithIdentifier:secondControllerSegueIdentifier sender:self];
} else {
[self.containerViewController performSegueWithIdentifier:firstControllerSegueIdentifier sender:self];
}
}

@end
```
MIT license.

0 comments on commit 8850018

Please sign in to comment.