Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-28-2012, 07:24 PM   #1 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default iOS 5 Container view controllers and custom transtions

A client of ours needed a prototype of an app that used a UI that was sort of like a tab bar controller, but not quite. The was a control sort of like a tab bar at the bottom, with items on the left side that selected a view controller on the top. Some of the view controllers also added a segmented control to the tab bar, however, that caused different view controller to appear.

Thus, none of iOS'es existing view controller organizers would work. (There are only a few: navigation controller, tab bar controllers, page controllers)

We decided to try out the new parent/child view controller scheme that's supported in iOS 5.

It has proven very easy to use, and very flexible. You can create your own parent view controllers that implement new behaviors. You can make any part of the screen be managed by another view controller, and swap it out for a different view controller at will. (Think tool palettes in photoshop, or game boards in a multi-game board game engine.)

I was able to quickly and easily create the client's variation of a tab bar controller, that managed a set of child view controllers, rather like the way a tab bar controller does. Further, I added the ability to swap between view controllers using a variety of different transitions, some provided by the OS, and some custom.

The key was the method transitionFromViewController:toViewController:dura tionptions:animations:completion: That one method gives you a lot of power in managing child view controllers. You can pass in one of a few standard apple transitions in the options parameter:
  • FlipFromLeft/right
  • CurlUp/down
  • CrossDissolve
  • FlipFromTop/bottom
  • FlipFromBottom

The animations block parameter lets you use standard UIView block animations, which makes slide, dissolve, grow/shrink, rotate, and other such transitions really easy.

Later, I decided to generalize this approach. I've created a general purpose "parent" view controller class. It has methods that let you register view controllers as child view controllers, and assign them to arbitrary container views. Once you've registered your child view controllers and the container view they belong to, there's a single call that lets you switch between view controllers using a wide variety of transitions.

I created a test-bed application that divides the screen into 2 "container" subviews, and installs 2 view controllers into each subview. Tapping on either view triggers a transition to the other view controller for that subview. I added a "combo box" control that lets you pick your transition.

I then went a little crazy, and created a whole family of different transitions. Here's the total list of animations that our parent view controller class supports:

crossDissolve,
slideFromRight,
slideFromLeft,
slideFromTop,
slideFromBottom,
flipFromRight,
flipFromLeft,
flipFromTop,
flipfromBottom,
curlUp,
curlDown,
growFromCenter,
shrinkToCenter,
/*------------
The transitions below use a CAAnimation, and don't use the transitionFromViewController:toViewController:dura tionptions:animations:completion method

This group of transtions uses a CAMaskLayer to either hide the old view or reveal the new view
*/
vBlindsRight,
vBlindsLeft,
vBlindsCascadeRight,
vBlindsCascadeLeft,

//This group of transitions "slices and dices" the contents of the view controllers and animates the pieces
vBlinds3DFlipRight,
vBlinds3DFlipLeft,


I'm most proud of the 3D cascade animation. That slices the view controller into a series of vertical "slats", and the animates each slat rising up off the screen and rotating in place, with the other view controller's content appearing on the back-side of the slat. The animation moves from left to right or right to left, creating a wave effect that is hypnotic to watch.

Here is a screen-shot of the test application, with the bottom view controller showing a cascade transition:



Sadly, a still image doesn't really do it justice.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-28-2012, 08:09 PM   #2 (permalink)
Just helping out.
 
Domele's Avatar
 
Join Date: Feb 2011
Posts: 2,565
Domele is on a distinguished road
Default

Question for you, what pushes you to create features in your classes that you don't currently need? I'm not talking about the small stuff, but like your complex animations in this controller. Or does your current project require all those animations?
__________________
If you are looking for a quality developer, I'm your man. Give me a PM if you are interested.

New app - See screenshots and details at www.globaclock.com.

If you want to thank me, click the link. Every click counts. If you want to do more, buy my app. A link is available on my website. Thanks.
Domele is offline   Reply With Quote
Old 01-28-2012, 09:45 PM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Domele View Post
Question for you, what pushes you to create features in your classes that you don't currently need? I'm not talking about the small stuff, but like your complex animations in this controller. Or does your current project require all those animations?

In that particular case, a desire to learn more about Core Animation. It was a learning project.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 02-11-2012, 11:01 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 8
Sportyguy_007 is on a distinguished road
Default Looks Great! Can you help me?

I am trying to implement:
Code:
[self transitionFromViewController:currentViewController
toViewController:nextViewController 
duration:1.0f 
options:UIViewAnimationOptionTransitionNone 
animations:^{
        currentViewController.view.alpha = 0;
        currentViewController.view.transform = CGAffineTransformMakeScale(2, 2);
    } completion:^(BOOL finished) {
        ...
    }];
but the currentViewController does not animate.

It just disappears and shows the nextViewController. I know this is serial simple but I have been coding nonstop for awhile and have hit a road block with this.

Just asking for some friendly help so I can make this deadline.

Thanks!
Sportyguy_007 is offline   Reply With Quote
Old 02-11-2012, 02:16 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Sportyguy_007 View Post
I am trying to implement:
Code:
[self transitionFromViewController:currentViewController
toViewController: nextViewController 
duration:1.0f 
options:UIViewAnimationOptionTransitionNone 
animations:^{
        currentViewController.view.alpha = 0;
        currentViewController.view.transform = CGAffineTransformMakeScale(2, 2);
    } completion:^(BOOL finished) {
        ...
    }];
but the currentViewController does not animate.

It just disappears and shows the nextViewController. I know this is serial simple but I have been coding nonstop for awhile and have hit a road block with this.

Just asking for some friendly help so I can make this deadline.

Thanks!
Things to check:

Were both currentViewController and nextViewController added as child view controllers of self (the parent view controller?) is currentViewController's a subview of the parent view controller's content?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 02-11-2012, 03:24 PM   #6 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 8
Sportyguy_007 is on a distinguished road
Default Checked

Quote:
Originally Posted by Duncan C View Post
Things to check:

Were both currentViewController and nextViewController added as child view controllers of self (the parent view controller?) is currentViewController's a subview of the parent view controller's content?
Ok I have a custom container view controller: ContainerViewController

I add the first child view controllers view as a subview of the ContainerViewController or more appropriately the ParentViewController's view. And set it as the currentViewController in the ContainerViewController.

I then call [self addChildViewController:currentViewController];

So roughly this seems to be set up correctly.

I have a button that calls the custom popViewController method, which is where I call transitionFromViewController: toViewController:

Inside this method I create my second child view controller called nextViewController.

I first call [self addChildViewController:nextViewController]; so that it and the currentViewController are both childs of the parent, ContainerViewController.

Then I call the transitionFromViewController: toViewController method.

I have tried this:
Code:
[self transitionFromViewController:currentViewController
toViewController:nextViewController
duration:1.0
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationTransitionFlipFromRight
animations:nil
completion:^(BOOL finished) {
        if (finished) {...}
    }];
but the nextViewController just appears over the top of everything instantly. No animation what so ever...this is driving me crazy because I have read the docs, watched wwdc 2011 session video on containment, and looked at other peoples examples, and yet the view just keeps popping above it all...

if i animate the nextViewController in the animations block, it will animate, but the currentViewController just disappears, or more rather gets covered up by the nextViewController.

If I set the nextViewController's frame halfway down the screen I can see the currentViewController flip to nothingness...

Also currentViewController and nextViewController are both strong properties and the view controllers themselves are created programatically, not using storyboards or nibs.

Joe

Last edited by Sportyguy_007; 02-11-2012 at 04:01 PM. Reason: Clarification on how the view controllers are created.
Sportyguy_007 is offline   Reply With Quote
Old 02-11-2012, 05:10 PM   #7 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by Sportyguy_007 View Post
Ok I have a custom container view controller: ContainerViewController

I add the first child view controllers view as a subview of the ContainerViewController or more appropriately the ParentViewController's view. And set it as the currentViewController in the ContainerViewController.

I then call [self addChildViewController:currentViewController];

So roughly this seems to be set up correctly.

I have a button that calls the custom popViewController method, which is where I call transitionFromViewController: toViewController:

Inside this method I create my second child view controller called nextViewController.

I first call [self addChildViewController:nextViewController]; so that it and the currentViewController are both childs of the parent, ContainerViewController.

Then I call the transitionFromViewController: toViewController method.

I have tried this:
Code:
[self transitionFromViewController:currentViewController
toViewController:nextViewController
duration:1.0
options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationTransitionFlipFromRight
animations:nil
completion:^(BOOL finished) {
        if (finished) {...}
    }];
but the nextViewController just appears over the top of everything instantly. No animation what so ever...this is driving me crazy because I have read the docs, watched wwdc 2011 session video on containment, and looked at other peoples examples, and yet the view just keeps popping above it all...

if i animate the nextViewController in the animations block, it will animate, but the currentViewController just disappears, or more rather gets covered up by the nextViewController.

If I set the nextViewController's frame halfway down the screen I can see the currentViewController flip to nothingness...

Also currentViewController and nextViewController are both strong properties and the view controllers themselves are created programatically, not using storyboards or nibs.

Joe
What I do is to add the child view controllers to the parent view controller (using addChildViewController) before I do anything. Add both children.

I then add the subview of the view controller that I want to show first.

When I'm ready to switch, I use transitionFromViewController:toViewController:dura tionptions:animations:completion: to switch the child view controllers around.

I've never had any trouble. It worked perfectly the first time I tried it.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 02-11-2012, 08:58 PM   #8 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 8
Sportyguy_007 is on a distinguished road
Default Posted example to Github

I added an example project to github.https://github.com/Sportyguy007/ContainerViewController

I am still at a loss.
Sportyguy_007 is offline   Reply With Quote
Old 02-12-2012, 01:30 PM   #9 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 8
Sportyguy_007 is on a distinguished road
Default Even using nibs.

Can anyone shed light on this? I tried creating another project except loading everything from nib files...still no animation when calling transitionFromViewController:toViewController:...

Does the project I posted on GitHub reflect this problem?

EDIT: I decided my question should really be in it's own thread, so I created a new one. It's at the following transitionFromViewController:toViewController: Animations.

Last edited by Sportyguy_007; 02-15-2012 at 06:23 PM.
Sportyguy_007 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 398
11 members and 387 guests
Atatator, condor304, FrankWeller, imac74, MAMN84, mraalex, n00b, PowerGoofy, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:59 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0