Nuthinking
Nuthinking

Reputation: 1331

presentViewController with custom transition

I would like to present a modal UIViewController with a different transitions to the ones available by the toolkit. Precisely I'd like an inverted animation compared to the slide from the bottom (UIModalTransitionStyleCoverVertical), present = slide in from the top, dismiss = slide out from the top.

I don't think there is a simply option for UIModalTransitionStyleCoverVertical to be inverted, so I guess I need to make one on my own.

I am also not using segue/storyboard either, not sure if this makes a difference.

I found some solutions which suggest to simply animate the new viewcontroller view and use presentViewController with the animated option as NO. Unfortunately the problem I have is that the background turns black straight away, even If I define the new viewcontroller view with clear background and not opaque.

Any idea how I could sort this out? Thanks a lot!

Upvotes: 3

Views: 2375

Answers (2)

Ahmad Baraka
Ahmad Baraka

Reputation: 1103

  1. Apply your custom animation with CATransition.

  2. Set modalPresentationStyle property for the presented view controller to UIModalPresentationCustom (available for iOS 7 or later). See also UIModalPresentationOverCurrentContext iOS8, or UIModalPresentationCurrentContext.

For my case I wanted to the same animation style, but I only needed to use UIModalPresentationOverCurrentContext for iOS 8.

Upvotes: 0

Nuthinking
Nuthinking

Reputation: 1331

I solved the not transparent background issue taking a screenshot and using it as background for the modal view controller.

Upvotes: 1

Related Questions