Aiy*_*ush 3 xcode swift swiftui
我这里有这段代码(放置在视图中):
if videoPos > 0.05 {
Text("It Worked Yay!")
playerPaused = false
}
Run Code Online (Sandbox Code Playgroud)
但是,由于“Type '()'无法符合'View'”,我不确定当 videoPos > 0.05 时如何更改变量。
这是视频位置:@Binding private(set) var videoPos: Double
我怎样才能克服这个问题?
您可以使用 onChange
}// End HStack
.onChange(of: videoPos, perform: { value in
if value > 0.05 {
playerPaused = false
}
})
Run Code Online (Sandbox Code Playgroud)
如果支持 iOS 13,则使用组合
}// End HStack
.onReceive(Just(videoPos), perform: { value in
if value > 0.05 {
playerPaused = false
}
})
Run Code Online (Sandbox Code Playgroud)
import Combine
Run Code Online (Sandbox Code Playgroud)