首页 > 解决方案 > 有什么方法可以阻止 SwiftUI Text 显示椭圆?

问题描述

我有一个文本视图,它根据状态变量的值动态显示不同的文本。当我循环浏览这些值时,如果新文本比旧文本长,我会在显示新文本之前暂时得到一个椭圆 (...)。遇到这种情况的代码如下所示:

Text(flashModeDescription(flashMode: appSettings.flashMode))
                        .font(.body).foregroundColor(.white)
                        .opacity(flashModeDescVisible ? 1: 0)
                        .animation(.easeIn(duration: 0.25))

Text 视图是 HStack 中的最后一项。

标签: iosswiftswiftui

解决方案


This is due to animation defined, so the following could fix

Text(flashModeDescription(flashMode: appSettings.flashMode))
                        .font(.body).foregroundColor(.white)
                        .animation(nil)                        // << here !!
                        .opacity(flashModeDescVisible ? 1: 0)
                        .animation(.easeIn(duration: 0.25))

so animation would affect only opacity


推荐阅读