I'm developing a content rich app that has 60+ screens I want to make animated segues between them without making storyboard arrows or connections,to semplify things, let's say I only have an app with 9 screens, A,B,C,D,E,F,G,H,I
if I use storyboards segues, then I will need to make a connection between each screen and the other back and forth... and end up with spaghetti/spider stuff, have a look at this screen for example, this is because almost any screen can lead to the other in the app i'm developing
so, what I need help with is the following,
1- How to make animated segues without having to use interface builder connections?
what I use is this
ram.vc = self.storyboard!.instantiateViewControllerWithIdentifier("MeBeforeSignUp") //MeBeforeSignUp
ram.vc.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
self.presentViewController(ram.vc, animated: true, completion: nil)
2-how to make it push on stack with a back button? to explain this, I mean, I want to segue in a long sequence of transitions with back buttons on top having the same order of navigation..
consider this sequence of navigation, from A -> B -> C -> ...
THE SEQUENCE : A->B->C->G->F->B->C->A->B->D->B->C I move in the sequence from [A] to ... [C] now I'm in [C], I have a back button that goes back to [B] now I'm in [B], I have a back button that goes back to [D] ... etc until I reach [A] without a back button because the stack is empty
what is the best way to have this feature added for a lot of screens ?
3- Why do UIModalTransitionStyle
not offer a lot of animations?
these are only the animations I can see in autocomplete
CoverVertical
CrossDissolve
FlipHorizontal
PartialCurl
4- are there more animations that I can use?
5- why aren't there animation options? for example CoverVertical
has no options for speed and (top to bottom and bottom to top)
6- for example the twitter iOS application has this infinite stack system, you can go from post to post to post ... tens of times with the back button having the stack system, what I'm aiming for is this, but now I have a question, what my question is, isn't that going to flood the ram? how do iOS manage that in a way to make sure that the app don't crash from ram flooding?
I'm looking for help really, it will be very appreciated.
Have a look at the UIViewControllerAnimatedTransitioning
protocol. It's a bit of a tough nut to crack, but once you do you will be able to create any animated transition you want without being bound by IB or its default animations.
Essentially, you will embed your initial view controller in a UINavigationController
as normal. Hooking up the AnimatedTransitioning
will allow you to intercept each Push and Pop in the navigation controller and dictate what animation they should use instead. This will give you the custom animations you seek, plus the normal navigation stack.
As for the back button, you would either need to show the navigation bar which would include it naturally, or add a button to your views that would pop the view controller from the stack.
------------- EDIT to provide point by point answers -------------
You should make use of the UIViewControllerAnimatedTransitioning
protocol I mentioned above. It's a big topic, but thankfully there are ample tutorials and explanations of how it works online. Confusing at first, but awesome once it settles in. Unfortunately not a cut and paste answer type situation.
If you embed your view controller A in a UINavigationController
, you get this behavior out of the box. If you don't want to see the bar at the top of the screen, you can hide it and programmatically call the popViewController
method when appropriate to go back one viewController in the stack.
Modally presented view controllers are not added to the navigation controller's stack, so I would avoid using presentViewController
or any modally presented transitions. In order to get the behavior you are after, you should instead push and pop your view controllers with the navigation controller rather than present. I do wish they gave us more default transitions, but developers are encouraged to create custom ones appropriate to their apps.
Using UIViewControllerAnimatedTranisitioning
you can create pretty much any transition you want. You can really get creative and give your app a unique feel this way.
Same as the answer to 4. You can control every aspect of every animation in your transition. It's entirely custom.
This is UINavigationController
's default behavior. You should be fine memory-wise as long as you don't leave a bunch of long running tasks on the view controllers alive in the stack. Unlikely you would be doing that anyway.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With