2017-08-10 133 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) 
    }