GKAutoScrollingView 0.1.2

GKAutoScrollingView 0.1.2

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最后发布2016年8月
SPM支持 SPM

George Kye 维护。



  • =

GKAutoScrollingView

codebeat badge

一个可定制的、易于使用的无限滚动视图,类似于 App Store 横幅。

Demo

安装

GKAutoScrollingView 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中

pod "GKAutoScrollingView"

示例

查看演示。

用法

1: 将 AutoScrollingView 添加到您的 UIViewController
2: 设置 dataSourcedelegate(可选)

class ViewController: UIViewController, AutoScrollingViewDataSource, AutoScrollingViewDelegate {
  var autoScrollView: AutoScrollingView!

  override func viewDidLoad() {
    super.viewDidLoad()
    autoScrollView = AutoScrollingView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 300))
    autoScrollView.dataSource = self
    autoScrollView.delegate = self
    self.view.addSubview(autoScrollView)
  }

}

3: 遵守 AutoScrollingViewdataSource

extension MyViewController: AutoScrollingViewDataSource{
  func createImageViews()->[UIImageView]{
    var array: [UIImageView] = []
    for index in 0...3 {
      let img = UIImageView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 300))
      img.image = UIImage(named: "\(index)")
      array.append(img)
    }
    return array
  }

  func setAutoScrollingViewDataSource(autoScrollingView: AutoScrollingView) -> [UIView] {
    return createImageViews()
  }
}

4: 遵守 AutoScrollingViewdelegate(所有都是可选的)

extension MyViewController: AutoScrollingViewDelegate{
  func autoScrollingView(autoScrollingView: AutoScrollingView, didSelectItem index: Int) {
    print("did select")
  }

  func autoScrollingView(autoScrollingView: AutoScrollingView, didChangeStatus status: ScrollingState) {
    print(status.rawValue)
  }

  func autoScrollingView(autoScrollingView: AutoScrollingView, didAutoScroll index: Int) {
    print("auto scrolling at index ", index)
  }
}

协议

数据源

返回用于 ScrollViewUIView 数组

  func setAutoScrollingViewDataSource(autoScrollingView: AutoScrollingView)->[UIView]

委托

返回所选视图的索引

optional func autoScrollingView(autoScrollingView: AutoScrollingView, didSelectItem index: Int)

在视图滚动之前返回 currentItem 的索引

optional func autoScrollingView(autoScrollingView: AutoScrollingView, didAutoScroll index: Int)

返回滑动自动化状态的 AutoScrollingView。(未暂停暂停

optional func autoScrollingView(autoScrollingView: AutoScrollingView, didChangeStatus status: ScrollingState)

方法

停止 ScrollView 的自动化

pauseScrolling()

开始滚动自动化(如果滚动已暂停)

startScrolling()

属性

设置 autoScrolling 之间的间隔。默认是 2.0 秒。

public var timerInterval: Double!

许可证

GKAutoScrollingView 在 MIT 许可下可用。有关更多信息,请参阅 LICENSE 文件。