Skip to content

Commit

Permalink
Fix alpha animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bunn committed Dec 18, 2024
1 parent c962d5a commit b507979
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import UIKit
final class RoundedPageSheetContainerViewController: UIViewController {
let contentViewController: UIViewController
private let allowedOrientation: UIInterfaceOrientationMask
let backgroundView = UIView()

private var interactiveDismissalTransition: UIPercentDrivenInteractiveTransition?
private var isInteractiveDismissal = false
Expand Down Expand Up @@ -52,8 +53,9 @@ final class RoundedPageSheetContainerViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .black
view.backgroundColor = .clear

setupBackgroundView()
setupContentViewController()
}

Expand Down Expand Up @@ -86,6 +88,20 @@ final class RoundedPageSheetContainerViewController: UIViewController {
}
}

private func setupBackgroundView() {
view.addSubview(backgroundView)

backgroundView.backgroundColor = .black
backgroundView.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
backgroundView.topAnchor.constraint(equalTo: view.topAnchor),
backgroundView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
backgroundView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
backgroundView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
}

private func setupContentViewController() {
addChild(contentViewController)
view.addSubview(contentViewController.view)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class RoundedPageSheetDismissalAnimator: NSObject, UIViewControllerAnimatedTrans
let fromView = fromViewController.view,
let contentView = fromViewController.contentViewController.view else { return }

let fromBackgroundView = fromViewController.backgroundView
let containerView = transitionContext.containerView

UIView.animate(withDuration: AnimatorConstants.duration,
Expand All @@ -74,7 +75,7 @@ class RoundedPageSheetDismissalAnimator: NSObject, UIViewControllerAnimatedTrans
initialSpringVelocity: AnimatorConstants.springVelocity,
options: .curveEaseInOut,
animations: {
fromView.alpha = 0
fromBackgroundView.alpha = 0
contentView.transform = CGAffineTransform(translationX: 0, y: containerView.bounds.height)
}, completion: { finished in
fromView.removeFromSuperview()
Expand All @@ -94,10 +95,11 @@ class RoundedPageSheetDismissalAnimator: NSObject, UIViewControllerAnimatedTrans
}

let containerView = transitionContext.containerView
let fromBackgroundView = fromViewController.backgroundView

let animator = UIViewPropertyAnimator(duration: AnimatorConstants.duration,
dampingRatio: AnimatorConstants.springDamping) {
fromView.alpha = 0
fromBackgroundView.alpha = 0
contentView.transform = CGAffineTransform(translationX: 0, y: containerView.bounds.height)
}

Expand Down

0 comments on commit b507979

Please sign in to comment.