|
7 | 7 |
|
8 | 8 | import UIKit |
9 | 9 |
|
| 10 | +@objc |
| 11 | +/// The delegate protocol informing about image slideshow state changes |
| 12 | +public protocol ImageSlideshowDelegate: class { |
| 13 | + /// Tells the delegate that the current page has changed |
| 14 | + /// |
| 15 | + /// - Parameters: |
| 16 | + /// - imageSlideshow: image slideshow instance |
| 17 | + /// - page: new page |
| 18 | + @objc optional func imageSlideshow(_ imageSlideshow: ImageSlideshow, didChangeCurrentPageTo page: Int) |
| 19 | + |
| 20 | + /// Tells the delegate that the slideshow will begin dragging |
| 21 | + /// |
| 22 | + /// - Parameter imageSlideshow: image slideshow instance |
| 23 | + @objc optional func imageSlideshowWillBeginDragging(_ imageSlideshow: ImageSlideshow) |
| 24 | + |
| 25 | + /// Tells the delegate that the slideshow did end decelerating |
| 26 | + /// |
| 27 | + /// - Parameter imageSlideshow: image slideshow instance |
| 28 | + @objc optional func imageSlideshowDidEndDecelerating(_ imageSlideshow: ImageSlideshow) |
| 29 | +} |
| 30 | + |
10 | 31 | /** |
11 | 32 | Used to represent position of the Page Control |
12 | 33 | - hidden: Page Control is hidden |
@@ -94,10 +115,14 @@ open class ImageSlideshow: UIView { |
94 | 115 | didSet { |
95 | 116 | if oldValue != currentPage { |
96 | 117 | currentPageChanged?(currentPage) |
| 118 | + delegate?.imageSlideshow?(self, didChangeCurrentPageTo: currentPage) |
97 | 119 | } |
98 | 120 | } |
99 | 121 | } |
100 | 122 |
|
| 123 | + /// Delegate called on image slideshow state change |
| 124 | + open weak var delegate: ImageSlideshowDelegate? |
| 125 | + |
101 | 126 | /// Called on each currentPage change |
102 | 127 | open var currentPageChanged: ((_ page: Int) -> ())? |
103 | 128 |
|
@@ -494,11 +519,13 @@ extension ImageSlideshow: UIScrollViewDelegate { |
494 | 519 |
|
495 | 520 | setTimerIfNeeded() |
496 | 521 | willBeginDragging?() |
| 522 | + delegate?.imageSlideshowWillBeginDragging?(self) |
497 | 523 | } |
498 | 524 |
|
499 | 525 | open func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { |
500 | 526 | setCurrentPageForScrollViewPage(primaryVisiblePage) |
501 | 527 | didEndDecelerating?() |
| 528 | + delegate?.imageSlideshowDidEndDecelerating?(self) |
502 | 529 | } |
503 | 530 |
|
504 | 531 | open func scrollViewDidScroll(_ scrollView: UIScrollView) { |
|
0 commit comments