imObjCSwifting
imObjCSwifting

Reputation: 743

Present View Controller right after Dismissing View Controller with no animation

I have a UIImagePickerController presented on screen. When I choose the photo I need to dismiss the PickerController then immediately present another PhotoEditController. Here is my code

picker.dismissViewControllerAnimated(false, completion: {
    self.presentViewController(editPhotoVC, animated: false, completion: nil)
})

There is a 0.1s flash between dismissing old VC and presenting new VC so the presentingViewController (self) is shown. How do I avoid that in an elegant solution not hacking it through? Thanks

Upvotes: 3

Views: 2702

Answers (3)

Abhinav
Abhinav

Reputation: 38162

The standard way of implementation is to dismiss first view controller (VC) with animation and present second VC with animation.

However, depending on your view hierarchy, you could also have your second VC loaded first and then present first VC on top of it. With this simply dismissing first VC without animation should show underneath second VC without delay.

Third approach, as LLooggaann suggested, don't dismiss first VC and simply present second VC. Once done, dismiss the entire view controller hierarchy in one shot.

Upvotes: 1

Lukas
Lukas

Reputation: 3433

That is most probably because dismiss is sent to the VC that presented the picker and it dismisses the picker modal vc and executes the completion handler after attempting to present the parent VC which is itself. one solution would be creating your own transition class, you can basically copy paste the code from here to do that

Upvotes: 0

user1232690
user1232690

Reputation: 491

You could instantiate PhotoEditController's instance, then do something like this:

instance.willMoveToParentViewController(controllerThatPresentsPicker)
controllerThatPresentsPicker.addChildViewController(instance)
controllerThatPresentsPicker.view.insertSubview(instance.view, belowSubview: picker.view)
instance.didMoveToParentViewController(controllerThatPresentsPicker)

It looks a bit like a hack though

Upvotes: 0

Related Questions