Post not yet marked as solved
Is it because you typed "\(chartData.high)" instead of just chartData.high? You’re passing a String instead of a numeric value on the y-axis.
Post not yet marked as solved
ShazamKit won’t recognize whether a user is singing a melody. Shazam only recognizes specific recordings.
I’m sorry that I don’t know the solution to your problem, but ShazamKit is not it.
Yes, that is what I was referring to. Incorrect information elsewhere on the web gave the impression that this changes double taps globally. Thank you for the clarification.
Post not yet marked as solved
Yes, there is: don't use two RoundedRectangles. 🙂
Instead, use one and mutate the values that you want to differ. Here's how I implemented it in your code:
struct ContentView: View {
@State var toggled = false
@Namespace var namespace
var body: some View {
VStack(spacing: 16) {
Toggle("Toggle", isOn: $toggled.animation(.linear(duration: 30)))
if toggled {
Spacer()
}
RoundedRectangle(cornerRadius: toggled ? 24 : 12, style: .continuous)
.fill(toggled ? .red : .blue)
.matchedGeometryEffect(id: "box", in: namespace)
.frame(width: toggled ? 200 : 100, height: toggled ? 100 : 200)
if !toggled {
Spacer()
}
}
.padding(24)
}
}
How it works:
toggled ? value1 : value2 returns value1 if toggled is true or value2 if toggled is false. This works for anything as long as both values are of the same type.
@State tells SwiftUI to update the view any time that toggled changes.
So any time you flip the switch, it toggles toggled which forces a recalculation of the view with new values for cornerRadius, .fill, width, and height, and after the recalculation, animates the changes according to your .animation parameters.
I think this gives precisely the kind of animation that you were looking for.
So any time you want to do something like this, instead of having two views that you switch between, use one view and mutate its values.
What about using the currencyFormatter.string(from: NSNumber) method to make a String and then just using that?