SWIFTUI:添加计时器,让横幅自动滚动吗?

问题描述 投票:-2回答:1

我有一个UIPageViewController以显示图像。我需要一个计时器,每5秒钟显示一个接一个的图像。如何使用计时器在5秒后启动事件以移至下一张图像?还是我使用错误的方式?

screenshot

ios swift uipageviewcontroller
1个回答
0
投票

使用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()
© www.soinside.com 2019 - 2024. All rights reserved.