使用Timer.publish
创建计时器实例字段,如下所示:
Timer.publish
然后使用任何视图的let images = [...] // Array of image names to show
@State var activeImageIndex = 0 // Index of the currently displayed image
let imageSwitchTimer = Timer.publish(every: 5, on: .main, in: .common)
.autoconnect()
修饰符转到下一张图像:
.onReceive()