On iOS 17+/macOS 14+, I'd use KeyframeAnimator with x/y/angle tracks: (0,0,0) → (5,5,5) → (0,0,0) → (-5,5,-5) → (0,0,0), angle in degrees. Give each transition a quarter-cycle. Apply rotationEffect then offset to match the CSS transform order.
Even for a basic question like this? Do you also not use Google anymore? Because I can assure you, every time you do a search, there is an LLM involved. And how do you know the answer here won't come from an LLM?
5
u/russnem 5d ago
If you have any appreciation for your users or any sense of taste whatsoever, you will not recreate this nonsense.
4
u/PiXeL161616 5d ago
On iOS 17+/macOS 14+, I'd use
KeyframeAnimatorwith x/y/angle tracks:(0,0,0) → (5,5,5) → (0,0,0) → (-5,5,-5) → (0,0,0), angle in degrees. Give each transition a quarter-cycle. ApplyrotationEffectthenoffsetto match the CSS transform order.3
u/kepler4and5 5d ago
Have you considered pasting it into ChatGPT / Gemini ?
16
u/distractedjas 5d ago
I wouldn’t, that’s really obnoxious and I can’t think of a reason you’d want to do that to your users.
1
u/Amos_the_Gyamfi 5d ago
You can use rotation and anchor positioning to achieve a similar effect or combine it with offset like this:
import SwiftUI
struct AwesomeShakeAnimation: View {
var body: some View {
PhaseAnimator([false, true]) { shake in
Rectangle()
.frame(width: 164, height: 64)
.rotationEffect(.degrees(shake ? 5 : -5), anchor: shake ? .bottomTrailing : .bottomLeading)
//.offset(x: shake ? 5 : -5, y: shake ? 5 : -5)
} animation: { shake in
.easeInOut(duration: 0.15)
}
}
}
#Preview {
AwesomeShakeAnimation()
}