Skip to content

Instantly share code, notes, and snippets.

@timothycosta
Last active May 15, 2024 13:19
Show Gist options
  • Save timothycosta/78e87544a90ce1670548407aac556ab3 to your computer and use it in GitHub Desktop.
Save timothycosta/78e87544a90ce1670548407aac556ab3 to your computer and use it in GitHub Desktop.
Create a SwiftUI Animation with the correct curve and duration from UIKit keyboard notifications
func animation(from notification: Notification) -> Animation? {
guard
let info = notification.userInfo,
let duration = info[UIResponder.keyboardAnimationDurationUserInfoKey] as? Double,
let curveValue = info[UIResponder.keyboardAnimationCurveUserInfoKey] as? Int,
let uiKitCurve = UIView.AnimationCurve(rawValue: curveValue)
else {
return nil
}
let timing = UICubicTimingParameters(animationCurve: uiKitCurve)
return Animation.timingCurve(
Double(timing.controlPoint1.x),
Double(timing.controlPoint1.y),
Double(timing.controlPoint2.x),
Double(timing.controlPoint2.y),
duration: duration
)
}
@shywoody
Copy link

shywoody commented Mar 8, 2023

thx a lot, i'll try. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment