2016-08-08 35 views
0

我使用的NSTimer一個UICollectionView連續滾動,這裏是代碼連續滾動UICollectionView iOS時未檢測到點擊?

let timer = NSTimer(timeInterval: 0.1, target: self, selector: #selector(HomeViewController.scrollToNextCard), userInfo: nil, repeats: true) 
NSRunLoop.currentRunLoop().addTimer(timer!, forMode: NSDefaultRunLoopMode) 

func scrollToNextCard(){ 
    UIView.animateWithDuration(0.1, delay: 0.0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { 
       // I am changing the contentOffset of collectionview for continuous scrolling 
     }, completion: {(finished:Bool) in 

    }) 

當任何可見細胞的敲擊時滾動過程中,委託的方法didSelectItemAtIndexpath不會被調用。如何在維持滾動收集視圖的同時實現竊聽檢測。請幫助感謝

+0

嘗試'NSRunLoopCommonModes',而不是'NSDefaultRunLoopMode'。 – Santosh

+0

沒有不行。 – coder123

回答

1

我發現了同樣的答案,我不得不在動畫塊上添加的allowUserInteraction標誌作爲代碼:

func scrollToNextCard(){ 
    UIView.animateWithDuration(Constants.CardFlowTimeInterval, delay: 0.0, options: [.CurveEaseInOut,.AllowUserInteraction], animations: { 
     }, completion: {(finished:Bool) in 
    }) 
}