Post

Replies

Boosts

Views

Activity

matchedGeometryEffect works incorrectly
I am practising matchedGeometryEffect. struct ContentView: View { @Namespace var tem @State var isTemp: Bool = true var body: some View{ ZStack{ if isTemp{ Circle() .matchedGeometryEffect(id: "haha", in: tem, anchor: .center) .foregroundColor(.green) .frame(width: 200, height: 200) }else{ Rectangle() .matchedGeometryEffect(id: "haha", in: tem, anchor: .center) .foregroundColor(.blue).opacity(0.4) .frame(width: 400, height: 600) } Button { withAnimation(.linear(duration: 5)){ isTemp = false } } label: { Text("switch") } } } } If I set anchor to top, it works well with the tops of both shapes remaining alignment. When I set anchor to center, I expect both shapes should stay at the center point of screen and extend around. However, only the rectangle stays still as expected, while the circle descends like bottom anchor effect. What's more, if I set anchor to bottom, the circle descends more quickly. Is it a normal behavior? Do I miss anything?
0
0
673
Mar ’23
text editor & text field layout issue in list
I need use a built-in text editor, a custom text editor and a built-in text field in the same list. I encounter a couple of problems: set font to .body: The row height of custom text editor is bigger than the other two. The custom text editor can't stay in the center of the row by vertical. The text editor can't align to text field by leading. set font to .title: In addition to problem 1 behavior, the built-in text editor can't stay in the center of the row by vertical either. How could I make the three components to have the same row height and align center in vertical and align by leading? struct ContentView: View {     @State private var text = "hello"     @State private var text2 = ""     var body: some View {         List{             Section("title"){                 CustomTextEditor(text: $text)                 TextEditor(text: $text)                     .font(.title)                 TextField("hello", text: $text2)                     .font(.title)             }         }     } } struct CustomTextEditor: UIViewRepresentable{     @Binding var text: String          func makeUIView(context: Context) -> UITextView {         let textView = UITextView()         textView.isScrollEnabled = false         textView.font = UIFont.preferredFont(forTextStyle: .title1)         textView.text = text         return textView     }     func updateUIView(_ uiView: UITextView, context: Context) {              } }
0
0
640
Mar ’23