我正在嘗試為文本設定影片以使其在螢屏上滾動,(使用它來制作股票應用程式),我無法讓它完全離開螢屏,有人可以幫忙...
這是我到目前為止所擁有的
let text = "Some text to animate"
private var is = true
var body: some View {
VStack {
Text(text)
.fixedSize()
.frame(width: 100, alignment: is ? .trailing : .leading)
.animation(Animation.linear(duration: 5).repeatForever())
}
uj5u.com熱心網友回復:
一種可能的解決方案是使用帶有 .move 不對稱過渡的單個文本。
這是一個簡化的演示。使用 Xcode 13.4 / iOS 15.5 測驗

主要部分:
var body: some View {
GeometryReader { gp in
VStack {
Text(text)
.fixedSize()
.frame(width: gp.size.width textWidth, alignment: .trailing)
.id(go)
.transition(transition)
.onAppear{ go.toggle() }
.animation(animation, value: go)
}
}.fixedSize(horizontal: false, vertical: true)
}
GitHub 上的測驗模塊
uj5u.com熱心網友回復:
像這樣?go如果為真,它使用 .offset 移動文本。
let text = "Some text to animate"
@State private var go = false
var body: some View {
VStack {
Text(text)
.fixedSize()
.frame(width: 100)
.offset(x: go ? 300 : 0, y: 0)
.animation(Animation.linear(duration: 3).repeatForever(), value: go)
.onAppear{self.go.toggle()}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/495036.html
