martinnormark / HalfModalPresentationController

Modal presentation that takes up half the screen. Swipe down to dismiss.
http://martinnormark.com/presenting-ios-view-controller-as-bottom-half-modal/
MIT License
471 stars 67 forks source link

completion not called on UIView.animate on ios 10 and ios 12 #18

Open armintelker opened 6 years ago

armintelker commented 6 years ago

the completion is not called on ios 10 and ios 12. this is strange. can you reproduce this?

HalfModalTransitionAnimator.swift

        UIView.animate(withDuration: transitionDuration(using: transitionContext), animations: {
            if self.edge == .maxYEdge {
                from.view.frame.origin.y = 800
            } else {
                from.view.alpha = 0
            }
        }, completion: { _ in
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
        })
punithbm commented 6 years ago

@martinnormark Facing same issue here

apparition47 commented 6 years ago

Noticed the same issue on my iPhone 6 (10.3.1). iOS 11 and 12 are okay.

Still looking into a proper solution but a temp workaround could be:

// HalfModalTransitionAnimator.swift
// @objc func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
if #available(iOS 11.0, *) {
    UIView.animate(withDuration: self.transitionDuration(using: transitionContext), animations: {
        from?.view.frame.origin.y = 800
    }) { _ in
        transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
    }
else {
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
        transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
    }
}
punithbm commented 6 years ago

@apparition47 iOS 12 also has same issue

apparition47 commented 6 years ago

For whatever reason the UIPanGestureRecognizer's onPan() selector isn't receiving events and so the transition never completes and my modal is stuck.

//iOS 10 console finished transition animating... start interactive

//iOS 11 //finished transition //animating... //start interactive //animate completed //dismissal did end: true //done dismiss animation

Changing this seemed to fix my issue on iOS 10 and allow the transition to complete:

// CardModalTransitioningDelegate.swift
var interactiveDismiss = false
jsndev commented 5 years ago

iOS 10.3 also has same issue var interactiveDismiss = false This solved my problem.

tks @apparition47

pmaksimov commented 5 years ago

Have found a solution on this

override func startInteractiveTransition(_ transitionContext: UIViewControllerContextTransitioning) { super.startInteractiveTransition(transitionContext) finish() }

in HalfModalInteractiveTransition.swift

pmaksimov commented 5 years ago

@apparition47 That doesn't solves the issue. It only makes transition non-interactive as far as I see.

parvshkhan commented 5 years ago

Wow great solution I was trouble with this also var interactiveDismiss = false fixed it.