我是 SwiftUI 的新手,试图reverse在 Android 中制作类似的东西LinearLayoutManager
messagesRecyclerView = view.findViewById(R.id.messagesRecyclerView);
manager = new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, true); // => true means reverse layout
messagesRecyclerView.setLayoutManager(manager);
Run Code Online (Sandbox Code Playgroud)
在这种情况下,一切都是从下到上的。
我能找到的所有有用的东西都是tableview反向的:
从底部加载 tableview,向上滚动(反向 tableview)(iOS)
//In ViewDidLoad
conversationTableView.transform = CGAffineTransform(rotationAngle: -(CGFloat)(Double.pi));
//In cellForRowAtIndexPath
cell.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi));
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将它添加到List(似乎它只是 TableView 的包装器)。这里的另一种方法:如何从底部向上填充 UITableView?
//In ViewDidLoad
conversationTableView.transform = CGAffineTransform(rotationAngle: -(CGFloat)(Double.pi));
//In cellForRowAtIndexPath
cell.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi));
Run Code Online (Sandbox Code Playgroud)
我的假设是得到一些东西.onAppear或override方法来完成这项工作。
似乎 SwiftUI 太年轻,无法深入。
另一个问题:他们是否有 API 可以在 List 中以编程方式滚动?
希望我没有重复任何问题。
将其用于匿名聊天应用https://en.lonje.com/
随着reverted List在 SwiftUI 中继续研究How to make List reversed in SwiftUI。
在恢复列表中获得奇怪的间距,看起来像额外的 UITableView 页眉/页脚。
struct ContentView: View {
@State private var ids = ["header", "test2"]
@State private var text = "text"
init() {
UITableView.appearance().tableFooterView = UIView()
UITableView.appearance().separatorStyle = .none
}
var body: some View {
ZStack (alignment: .bottomTrailing) {
VStack {
List {
ForEach(ids, id: \.self) { id in
Group {
if (id == "header") {
VStack {
Text("Test")
.font(.largeTitle)
.fontWeight(.heavy)
Text("header")
.foregroundColor(.gray)
}
.scaleEffect(x: 1, y: …Run Code Online (Sandbox Code Playgroud)