UI: scrollView 里面的图片 自动循环, 当然要使用 计时器。
func showData(){
scrollView.pagingEnabled = true
scrollView.bounces = false
//这个功能好
````````
self.start()
}
extension FPageBannerCell {
func start() {
self.timer = NSTimer(timeInterval: 2.0 , target: self, selector: #selector(nextPage(_:)) , userInfo: nil, repeats: true)
NSRunLoop.mainRunLoop().addTimer(self.timer!, forMode: NSDefaultRunLoopMode)
}
func nextPage(timer: NSTimer){
var page = self.pageControl.currentPage + 1
if page == (bannerArray?.count)! {
page = 0
}
self.scrollView.setContentOffset( CGPointMake(CGFloat(page)*kScreenWidth, 0) , animated: true)
}
func stopTimer(){
self.timer?.invalidate()
}
func scrollViewDidScroll(scrollView: UIScrollView) {
let number = Int( scrollView.contentOffset.x/kScreenWidth + 0.5 )
self.pageControl.currentPage = number
}
func scrollViewWillBeginDragging(scrollView: UIScrollView) {
self.stopTimer()
}
func scrollViewDidEndDragging(scrollView: UIScrollView, willDecelerate decelerate: Bool) {
self.start()
}
}