2017-08-10 53 views
0

我在Xcode中使用Swift 3中的iCarousel。我试图让它像滑动横幅一样工作。我有这个功能:重复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。它的工作原理,但我认为它不如它可能。切换到另一个视图后,滚动继续。当我看到视图时,旋转木马会在什么位置才能使其滚动,这是最好的方法?

+1

可能会有所帮助 https://stackoverflow.com/questions/44950769/autoscrolling-infinite-effect-in-linear-type-of-icarousel -in-swift/44951362#44951362 –

+0

也需要更多解释。 –

+0

该链接很有帮助,谢谢 –

回答

0

什么解决了这个问题:

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) 
    }