Skip to content

Commit

Permalink
Merge pull request #79 from BottleRocketStudios/transitionIssue_iOS13
Browse files Browse the repository at this point in the history
Fix an transition issue in iOS 13
  • Loading branch information
wmcginty committed Sep 16, 2019
2 parents 17e5250 + 20fb7ab commit 6728732
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
[Will McGinty](https://github.com/willmcginty)
[#77](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/77)

* Fix a transitionting issue where appearance callbacks were unbalanced in iOS 13.
[Will McGinty](https://github.com/willmcginty)
[#79](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/79)

## 1.6.0 (2019-08-29)

##### Enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,19 @@ import UIKit

/// This class is internal to the framework. It is the internal default transition animator used by the ContainerViewController when its delegate does not provide one.
class DefaultContainerTransitionAnimator: NSObject, UIViewControllerAnimatedTransitioning {

// MARK: Properties
private var interruptibleAnimator: UIViewPropertyAnimator?

// MARK: ContainerViewControllerAnimatedTransitioning

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

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
interruptibleAnimator?.startAnimation()
}

func interruptibleAnimator(using transitionContext: UIViewControllerContextTransitioning) -> UIViewImplicitlyAnimating {
guard let destination = transitionContext.view(forKey: .to), let source = transitionContext.view(forKey: .from) else {
guard let destinationController = transitionContext.viewController(forKey: .to), let destination = destinationController.view else {
fatalError("The context is improperly configured - requires both a source and destination.")
}

if let animator = interruptibleAnimator {
return animator
}

let duration = transitionDuration(using: transitionContext)
let timingParameters = UICubicTimingParameters(animationCurve: .easeInOut)
let propertyAnimator = UIViewPropertyAnimator(duration: duration, timingParameters: timingParameters)
propertyAnimator.addAnimations {
UIView.transition(from: source, to: destination, duration: duration, options: [.transitionCrossDissolve]) { finished in
transitionContext.completeTransition(finished)
}
}

propertyAnimator.addCompletion { [weak self] animatingPosition in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
self?.interruptibleAnimator = nil
}

interruptibleAnimator = propertyAnimator
return propertyAnimator
transitionContext.containerView.addSubview(destination)
destination.frame = transitionContext.finalFrame(for: destinationController)
transitionContext.completeTransition(true)
}
}

0 comments on commit 6728732

Please sign in to comment.