So have a stack with three view controllers where A is root, B is first modal view controller and C is third modal vc. I would like to go from C to A at once. I have tried this solution to dismiss.It does work but not in a correct way. That is when the last view controller is dismissed it will breifly show the second view controller before the first is shown. What I'm looking for is a way to get from the third vc to the first in one nice animation without noticing the second view. Any help on this is greatly appriciated.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- how do you prevent page scroll in textarea on mobi
- Custom UITableview cell accessibility not working
相关文章
- Could I create “Call” button in HTML 5 IPhone appl
- Unable to process app at this time due to a genera
- How do you detect key up / key down events from a
- “Storyboard.storyboard” could not be opened
- Open iOS 11 Files app via URL Scheme or some other
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- Can not export audiofiles via “open in:” from Voic
- XCode 4.5 giving me “SenTestingKit/SenTestKit.h” f
Be sure that you're only calling
dismissModalViewControllerAnimated:
once.I have found that asking to dismiss each stacked modal view controller will cause both of them to animate.
You have:
A =modal> B =modal> C
You should only call
[myViewControllerA dismissModalViewControllerAnimated:YES]
If you use
[myViewControllerB dismissModalViewControllerAnimated:YES]
, it will dismiss C, and not B. In normal (unstacked) use, it would dismiss B (due to the responder chain bubbling the message up to A). In the stacked scenario that you describe B is a parent view controller and this takes precedence over being a modal view controller.What you want to use is
popToRootViewControllerAnimated:
. It gets you to the root controller without showing all the intervening ones.For anyone looking for a work around you can do this:
Here's the code:
You may dismiss these modalViewControllers at your rootViewController.
Although the accepted answer did work for me, it may be outdated now and left a weird looking animation where the topmost modal would immediately disappear and the animation would be on the rear modalview. I tried many things to avoid this and ended up having to use a bit of a hack to have it look nice. Note:(only tested in iOS8+, but should work iOS7+)
Basically, viewControllerA creates a
UINavigationController
withviewControllerB
as the rootview and presents it modally.Now in
viewControllerB
we are going to presentviewControllerC
the same way, but after we present it, we are going to put a snapshot ofviewControllerC
over the view layer onviewControllerB
's navigation controller. Then, whenviewControllerC
disappears during dismissal, we won't see the change and the animation will look beautiful.Below are my helper functions that are used to present the view and handle dismissal. One thing to note, I am using Purelayout for adding auto layout constraints. You can modify this to add them manually or get Purelayout at https://github.com/PureLayout/PureLayout
Now we just need to ensure we have the dismissBlock defined as a property in ViewControllerC.h (you can obviously replace this whole part with delegate methods or other equally as exciting design patterns, the important part is to handle dismissal at the viewControllerB level)
Hope this helps, happy programming :)