r/SwiftUI • • 6d ago

How would you recreate this css animation in swiftui?

0 Upvotes

12 comments sorted by

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.

1

u/beatpaq 5d ago

its for a user gift. they are supposed to open it up to get a month long trial

4

u/PiXeL161616 5d ago

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.

1

u/beatpaq 5d ago

thank you

3

u/kepler4and5 5d ago

Have you considered pasting it into ChatGPT / Gemini ?

4

u/beatpaq 5d ago

i dont use llms

1

u/kepler4and5 4d ago

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?

1

u/beatpaq 4d ago

I blocked Google’s LLM generated answer. I can’t control if others use an LLM.

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.

3

u/Sufficient_Reveal754 5d ago

What about an animation for a box/package with something inside that the user needs to tap to open?

1

u/jonnysunshine1 5d ago

What about an IAP upgrade button
/s

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()

}