Customizable UIModalTransitionStyle Swift 4

692 Views Asked by At

is there a way to make a Customizable UIModalTranstitionStyle in a function easily so that the function can be customized and reused for multiple viewControllers when presenting them

Example:

func customTransition() -> UIModalTransitionStyle  {
        //other things here to customize transition
    }

its just that the standard .crossdissolve ,.fliphorizontal and all those arent what i need so i was just wondering if you could because i did it with a UIView

func popIn(yourView : UIView) {

        yourView.transform = CGAffineTransform(scaleX: 0.01, y: 0.01)
        UIView.animateKeyframes(withDuration: 0.2, delay: 0.0, options: UIViewKeyframeAnimationOptions.calculationModeDiscrete, animations: {
            yourView.transform = .identity
        }, completion: nil)
        self.view.addSubview(yourView)
    }
1

There are 1 best solutions below

6
On BEST ANSWER

The way to write a custom presentation transition is to write a custom presentation transition. The procedure for doing that is straightforward and well documented:

  • set a transitioningDelegate

  • implement animationController(forPresented:presenting:source:)

  • provide an animation controller object

If you don't like that ("a bunch of NSObjects and writing super complex stuff"?) then don't try to customize the presentation transition. Conversely, if you want a custom transition animation, then do what it takes to make one.