Skip to content

Commit

Permalink
Added auto scrolling functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Bailey committed Oct 4, 2016
1 parent e065120 commit c659293
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Binary file modified .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion IZPageController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'IZPageController'
s.version = '0.1.0'
s.version = '0.2.0'
s.summary = 'Used to create easily scrolled views that snap to place.'

s.description = <<-DESC
Expand Down
23 changes: 21 additions & 2 deletions IZPageController/Classes/IZPageController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ open class IZPageController: UIViewController, UIScrollViewDelegate {
removeViewController(at: it.offset)
}
viewControllers = []
for _ in 0..<(delegate?.numberOfViewControllers() ?? 0) {
for index in 0..<(delegate?.numberOfViewControllers() ?? 0) {
viewControllers.append(nil)
}
updateViewControllers(area: .preload)
Expand Down Expand Up @@ -202,6 +202,25 @@ open class IZPageController: UIViewController, UIScrollViewDelegate {
return scrollView.frame.size
}

open func scrollToViewController(at index : Int, animated : Bool) {

let frame = frameForViewController(at: index)

if animated {
UIView.animate(withDuration: 0, animations: {
self.scrollView.scrollRectToVisible(frame, animated: true)

}, completion: { (success) in
if success {
self.updatePageIndex()
}
})
} else {
scrollView.scrollRectToVisible(frame, animated: false)
updatePageIndex()
}
}

open func updatePageIndex() {
if let pageIndex = pageIndex, previouslyReportedPageIndex != pageIndex {
previouslyReportedPageIndex = pageIndex
Expand All @@ -219,4 +238,4 @@ open class IZPageController: UIViewController, UIScrollViewDelegate {
updatePageIndex()
updateViewControllers(area: .preload)
}
}
}

0 comments on commit c659293

Please sign in to comment.