【发布时间】:2019-07-08 14:06:11
【问题描述】:
我正在 Swift UI 中构建一个聊天应用程序,当我在 "ChatView" 中时,我想查看最后写入的消息,因此当消息显示在屏幕上时 (finalView ) 我需要将视图的滚动条放在底部。
这是我正在使用的代码:
ScrollView {
ForEach(self.userController.userMessage.identified(by: \.self)) { message in
if message.from == UserService.currentUserID! {
HStack {
Spacer()
Text(message.message)
.bold()
.foregroundColor(Color.white)
.padding(8)
.background(Color.blue, cornerRadius: 8)
}
} else {
HStack {
Text(message.message)
.bold()
.foregroundColor(Color.white)
.padding(8)
.background(Color.gray, cornerRadius: 8)
Spacer()
}
.offset(y: 8)
}
}
}
}
我怎样才能将 ScrollView 默认放在底部?
【问题讨论】: