mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-07 04:53:54 +00:00
[ios] make modal screen animation smoother
Signed-off-by: Kiryl Kaveryn <kirylkaveryn@gmail.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
6a488a08a0
commit
7117a1b954
@@ -8,8 +8,10 @@ final class ModalPresentationAnimator {
|
||||
|
||||
private enum Constants {
|
||||
static let animationDuration: TimeInterval = kDefaultAnimationDuration
|
||||
static let springDamping: CGFloat = 0.85
|
||||
static let springDamping: CGFloat = 0.8
|
||||
static let springVelocity: CGFloat = 0.2
|
||||
static let controlPoint1: CGPoint = CGPoint(x: 0.25, y: 0.1)
|
||||
static let controlPoint2: CGPoint = CGPoint(x: 0.15, y: 1.0)
|
||||
}
|
||||
|
||||
static func animate(with stepAnimation: PresentationStepChangeAnimation = .slide,
|
||||
@@ -19,20 +21,29 @@ final class ModalPresentationAnimator {
|
||||
case .none:
|
||||
animations()
|
||||
completion?(true)
|
||||
|
||||
case .slide:
|
||||
UIView.animate(withDuration: Constants.animationDuration,
|
||||
delay: 0,
|
||||
options: .curveEaseOut,
|
||||
animations: animations,
|
||||
completion: completion)
|
||||
let timing = UICubicTimingParameters(controlPoint1: Constants.controlPoint1,
|
||||
controlPoint2: Constants.controlPoint2)
|
||||
let animator = UIViewPropertyAnimator(duration: Constants.animationDuration,
|
||||
timingParameters: timing)
|
||||
animator.addAnimations(animations)
|
||||
animator.addCompletion { position in
|
||||
completion?(position == .end)
|
||||
}
|
||||
animator.startAnimation()
|
||||
|
||||
case .slideAndBounce:
|
||||
UIView.animate(withDuration: Constants.animationDuration,
|
||||
delay: 0,
|
||||
usingSpringWithDamping: Constants.springDamping,
|
||||
initialSpringVelocity: Constants.springVelocity,
|
||||
options: .curveLinear,
|
||||
animations: animations,
|
||||
completion: completion)
|
||||
let velocity = CGVector(dx: Constants.springVelocity, dy: Constants.springVelocity)
|
||||
let timing = UISpringTimingParameters(dampingRatio: Constants.springDamping,
|
||||
initialVelocity: velocity)
|
||||
let animator = UIViewPropertyAnimator(duration: Constants.animationDuration,
|
||||
timingParameters: timing)
|
||||
animator.addAnimations(animations)
|
||||
animator.addCompletion { position in
|
||||
completion?(position == .end)
|
||||
}
|
||||
animator.startAnimation()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user