Xamarin.iOS modal transitions

Presenting view controllers modally is one of the ways to display specific view controller during navigation. The main feature of modality is that showing modal view controller is not added to navigation stack.
In the most cases presenting is executed with some animation.
I prepared a simple application to show you four basic built in animations.

  • Cover Vertical
  • Partial Curl
  • Flip Horizontal
  • Cross Dissolve

I prepared a short storyboard:

And MainViewController code:

public partial class MainViewController : UIViewController
    {
        public MainViewController(IntPtr handle) : base(handle)
        {
        }

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            coverVerticalBtn.TouchUpInside += (sender, e) => ShowViewController(UIModalTransitionStyle.CoverVertical);
            partialCurlBtn.TouchUpInside += (sender, e) => ShowViewController(UIModalTransitionStyle.PartialCurl);
            flipHorizontalBtn.TouchUpInside += (sender, e) => ShowViewController(UIModalTransitionStyle.FlipHorizontal);
            crossDissolveBtn.TouchUpInside += (sender, e) => ShowViewController(UIModalTransitionStyle.CrossDissolve);
        }

        public async void ShowViewController(UIModalTransitionStyle style)
        {
            var controller = this.Storyboard.InstantiateViewController("SecondViewController");
            controller.ModalTransitionStyle = style;

            await PresentViewControllerAsync(controller, true);
        }
    }

 

In second view controller I added one button, just for dismissing presented modal.

 

 public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            closeBtn.TouchUpInside += (sender, e) =>
            {
                DismissModalViewController(animateSwitch.On);
            };
        }

 

And here are the results:

Cover Vertical                                                            Cross Dissolve

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Partial Curl                                                               Flip Horizontal (my favourite)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

As developers we have an ability to create our own custom modal transitions.

To do it we are required to use 3 classes:

– UIPresentationController
– UIViewControllerAnimatedTransitioning
– UIViewControllerAnimatedTransitioningDelegate

More about creating custom modal transition in next posts. Enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *