swiftui - SwiftUI:文本动画在第二行不起作用
问题描述
当我在 TextField 中键入内容时,我试图确保在整个动态文本视图中具有一致的动画。
import SwiftUI
struct ContentView: View {
@ObservedObject var viewModel = ContentViewModel()
var body: some View {
VStack {
HStack {
Text("Write this word: ")
Text(String(viewModel.textValue))
}
TextField("Write here:", text: $viewModel.enteredTextValue)
.padding(10)
.border(Color.green, width: 1)
Text(viewModel.enteredTextValue)
.animation(.easeIn(duration: 0.5)) // added animation here.
Toggle(isOn: $viewModel.textsMatch) {
Text("Matching?")
}
.disabled(true)
.padding()
}.padding()
}
}
class ContentViewModel: ObservableObject {
@Published var textValue: String = "Hello"
@Published var enteredTextValue: String = "" {
didSet {
textsMatch = (enteredTextValue == textValue)
}
}
@Published var textsMatch: Bool = false
}
注意动画在第一行是平滑的,然后在第二行下降?
请对此提供任何帮助。
FYI 代码取自此处(组合框架)。
非常感谢!
解决方案
推荐阅读
- vb.net - 不断出现错误,“非静态方法需要一个目标
- r - varImp() 错误:试图从不是 S4 对象的对象(类“glm”)中获取插槽“响应”
- r - R通过函数添加前导零时出错
- java - TestNG - 无法添加字符串列表作为数据提供者
- python - 如何在多个子目录中使用 python 为文件添加扩展名
- azure - 使用 SSIS 获取 azure 容器中的 blob 列表
- c# - create multiple files using multiple threads c#
- unit-testing - 单元测试原则
- bash - 在 Mac OS Mojave 上设置全局环境变量
- r - 如何在 Rstudio 的 georob 包中插入更密集采样的辅助变量