定時(shí)器
NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(didTimer(_:)), userInfo: nil, repeats: true)
didTimer(_:)
func didTimer(timer: NSTimer) {
//兩種表示方法
//NSIndexPath
//位置: frame.origin
//獲取內(nèi)容的偏移量
let offset = collectionView.contentOffset
//根據(jù)位置獲取Cell
let indexPath = collectionView.indexPathForItemAtPoint(CGPoint(x: offset.x , y: 0))
if indexPath!.item == 4 {
//滾動某個(gè)Cell到可見區(qū)域
collectionView.scrollToItemAtIndexPath(NSIndexPath(forItem: 0, inSection: 0), atScrollPosition: .Left, animated: false)
collectionView.scrollToItemAtIndexPath(NSIndexPath(forItem: 1,inSection: 0), atScrollPosition: .Left, animated: true)
}
else {
collectionView.scrollToItemAtIndexPath(NSIndexPath(forItem: indexPath!.item + 1, inSection: 0), atScrollPosition: .Left, animated: true)
}
}