Schriftart zuckt, Animationsfehler - Swiftui

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Schriftart zuckt, Animationsfehler - Swiftui

by Anonymous » 15 Feb 2025, 05:51

Ich teste jetzt seit 3 ​​Stunden und ich verstehe nicht, warum dieses Verhalten bestehen. > Alle Animationstypen (.linear,. >
(Deaktivierung desselben Elements ist akzeptabel animiert)

minimal reproduzierbares Beispiel:

Code: Select all

struct ChipsView: View {

let title: String
@Binding var selectedString: String

private var isSelected: Bool { selectedString == title }
private let selectedColor = Color.red
private let unselectedColor = Color.gray
private let selectedFont: Font.Weight = .bold
private let unselectedFont: Font.Weight = .light

var body: some View {
Text(title)
.font(.system(
size: 56,
weight: isSelected ? selectedFont : unselectedFont
))
.foregroundColor(isSelected ? selectedColor : unselectedColor)
.contentShape(Rectangle())
.onTapGesture {
withAnimation(.bouncy(duration: 0.3)) {
selectedString = isSelected ? "" : title
}
}
}
}

struct ChipsView_CustomPreview: View {
@State var selectedString: String = ""

var body: some View {
HStack {
ForEach(["11","22","33","44","55"], id: \.self) { str in
ChipsView(title: str, selectedString: $selectedString)
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.black)
}
}

#Preview {
ChipsView_CustomPreview()
}


Top