Schriftart zuckt, Animationsfehler - SwiftuiIOS

Programmierung für iOS
Anonymous
 Schriftart zuckt, Animationsfehler - Swiftui

Post by Anonymous »

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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post