Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ImageSlideshow/Classes/Core/ImageSlideshow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ open class ImageSlideshow: UIView {

/// Called on scrollViewDidEndDecelerating
open var didEndDecelerating: (() -> ())?

/// Called on scrollTap
open var didTap: ((_ page: Int) -> ())?

/// Currenlty displayed slideshow item
open var currentSlideshowItem: ImageSlideshowItem? {
Expand Down Expand Up @@ -219,6 +222,8 @@ open class ImageSlideshow: UIView {
if #available(iOS 11.0, *) {
scrollView.contentInsetAdjustmentBehavior = .never
}
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))
scrollView.addGestureRecognizer(tapGesture)
addSubview(scrollView)

if let pageIndicator = pageIndicator {
Expand Down Expand Up @@ -482,6 +487,11 @@ open class ImageSlideshow: UIView {
setCurrentPage(currentPage, animated: true)
}
}

@objc private func handleTap() {
let page: Int = Int(scrollView.contentOffset.x/scrollView.frame.size.width)
didTap!(page-1)
}
}

extension ImageSlideshow: UIScrollViewDelegate {
Expand Down