How to make List reversed in SwiftUI

后端 未结 2 459
栀梦
栀梦 2021-02-06 15:52

I\'m new in SwiftUI, trying to make something like reverse in Android LinearLayoutManager

mess         


        
相关标签:
2条回答
  • 2021-02-06 16:07

    @cipais's answer worked well. https://stackoverflow.com/a/61036551/12208004

    List(chatController.messages, id: \.self) { message in
        MessageView(message.text, message.isMe)
            .rotationEffect(.radians(.pi))
            .scaleEffect(x: -1, y: 1, anchor: .center)
    }
    .rotationEffect(.radians(.pi))
    .scaleEffect(x: -1, y: 1, anchor: .center)
    
    0 讨论(0)
  • 2021-02-06 16:16

    There is a trick on UITableView that you flip the table and each cell. So it appears to be filling from bottom. You can do this trick in SwiftUI too:

    Fully Working Demo:

    struct ContentView: View {
        @State private var ids = [String]()
    
        init() {
            UITableView.appearance().tableFooterView = UIView()
            UITableView.appearance().separatorStyle = .none
        }
    
        var body: some View {
            ZStack {
                List(ids, id: \.self) { id in
                    Text(id).scaleEffect(x: 1, y: -1, anchor: .center)
                }.scaleEffect(x: 1, y: -1, anchor: .center)
    
                Button("Touch") {
                    self.ids.append(UUID().uuidString)
                }
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题