gpt4 book ai didi

swift - 重复 iCarousel 的滚动

转载 作者:行者123 更新时间:2023-11-28 15:23:15 24 4
gpt4 key购买 nike

我在 Xcode 中使用 Swift 3 中的 iCarousel。我试图让它像滑动横幅一样工作。我有这个功能:

func animate() {
DispatchQueue.global(qos: .userInteractive).async {
self.carousel.scrollToItem(at: 0, animated: false)

while(true){
sleep(3)
self.carousel.scroll(byNumberOfItems: 1, duration: 0.3)
}
}
}

我在 viewDidLoad 中调用它。它有效,但我认为它不如预期的那么好。在我切换到另一个 View 后,滚动继续进行。当我看到旋转木马所在的 View 时,让它只滚动的最佳方法是什么?

最佳答案

是什么解决了问题:

var timer: Timer!

self.timer = Timer.scheduledTimer(timeInterval: 3, target: self, selector: #selector(self.handleTimer), userInfo: nil, repeats: true)

func handleTimer(){
self.carousel.scroll(byNumberOfItems: 1, duration: 0.3)
}

关于swift - 重复 iCarousel 的滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45614209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com