0
votes

I'm presenting modally UIViewController with UIModalPresentationCustom so I'm using also UIPresentationController. My ViewController which I'm presenting has set clear color for background ( In the storyboard picture I set a blue color to show which view is transparent ), but also has a UIView with white color.

storyboard picture here

There's something weird when I'm tapping on close button that is in a half outside white view. When I'm tapping that button, then some black artifacts shows, and it occurres only when close button has position like on the picture and there is a white view. If I move button up and it is entirely on a white view there will be no black artifacts. Also when I set clear color for this white view, so all my viewcontroller will have transparent background - there will be no artifacts.

Maybe anyone has this problem before ?

1
Try setting a break point in your close func and inspecting the frames (if you aren't familiar with icon go via. menu Debug > View Debugging > Capture View Hierarchy). See what view is turning black. If that doesn't help, post your viewcontroller's presentation and dismissal processes. - mmr118

1 Answers

2
votes

@moni15, I was trying to debug view hierarchy before but there's no black artifacts visible, also when I'm turning on view frames everything is looking fine. This looks like some rendering problem, or maybe iOS bug ?

Here's code for Presentation and Dimiss transition :

    class TransitionPresentationAnimator: NSObject, UIViewControllerAnimatedTransitioning {

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return 0.3
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!
        let containerView = transitionContext.containerView

        let animationDuration = self .transitionDuration(using: transitionContext)

        toViewController.view.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
        toViewController.view.layer.shadowColor = UIColor.black.cgColor
        toViewController.view.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
        toViewController.view.layer.shadowOpacity = 0.3
        toViewController.view.layer.cornerRadius = 4.0
        toViewController.view.clipsToBounds = true

        containerView.addSubview(toViewController.view)

        UIView.animate(withDuration: animationDuration, animations: { () -> Void in
            toViewController.view.transform = CGAffineTransform.identity
        }, completion: { (finished) -> Void in
            transitionContext.completeTransition(finished)
        })
    }
}

class TransitionDismissAnimator : NSObject, UIViewControllerAnimatedTransitioning {

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return 0.3
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        let fromViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
        let animationDuration = self .transitionDuration(using: transitionContext)

        UIView.animate(withDuration: animationDuration, animations: { () -> Void in
            fromViewController.view.alpha = 0.0
            fromViewController.view.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
        }) { (finished) -> Void in
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
        }
    }
}

Solved ! Problem was in TransitionPresentationAnimator class, and CGAffineTransform which was doing something wrong. Now I'm not using it anymore. I'm pasting my code if anyone will have similiar problem :

class TransitionPresentationAnimator: NSObject, UIViewControllerAnimatedTransitioning {

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        return 0.3
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        to = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to)!
            from = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from)!
            let container = transitionContext.containerView
            container.addSubview(to.view)

            to.view.bounds.origin = CGPoint(x: 0, y: -from.view.bounds.size.height)
            UIView.animate(withDuration: 0.6, delay: 0.0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: [.curveEaseOut], animations: {
                self.to.view.bounds = self.from.view.bounds
            }) { (completed) in
                transitionContext.completeTransition(completed)
            }
    }
}