diff --git a/Example/ImageSlideshow.xcodeproj/project.pbxproj b/Example/ImageSlideshow.xcodeproj/project.pbxproj index b809b4a6..7b032ffe 100644 --- a/Example/ImageSlideshow.xcodeproj/project.pbxproj +++ b/Example/ImageSlideshow.xcodeproj/project.pbxproj @@ -27,6 +27,8 @@ D0E8A9F51D97EB94007EC517 /* UIImage+AspectFit.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0E8A9EE1D97EB94007EC517 /* UIImage+AspectFit.swift */; }; D0E8A9F61D97EB94007EC517 /* UIImageView+Tools.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0E8A9EF1D97EB94007EC517 /* UIImageView+Tools.swift */; }; D0E8A9F71D97EB94007EC517 /* ZoomAnimatedTransitioning.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0E8A9F01D97EB94007EC517 /* ZoomAnimatedTransitioning.swift */; }; + E6D20C7F24DD6427005CFB3C /* arrow-right-64x.png in Resources */ = {isa = PBXBuildFile; fileRef = E6D20C7D24DD6426005CFB3C /* arrow-right-64x.png */; }; + E6D20C8024DD6427005CFB3C /* arrow-left-64x.png in Resources */ = {isa = PBXBuildFile; fileRef = E6D20C7E24DD6426005CFB3C /* arrow-left-64x.png */; }; F539204C210F03610057EFB3 /* SwiftSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = F539204B210F03600057EFB3 /* SwiftSupport.swift */; }; F802998F20CE9EA7009D64DD /* PageIndicatorPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = F802998E20CE9EA7009D64DD /* PageIndicatorPosition.swift */; }; F802999020CE9EA7009D64DD /* PageIndicatorPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = F802998E20CE9EA7009D64DD /* PageIndicatorPosition.swift */; }; @@ -74,6 +76,8 @@ D0E8A9EE1D97EB94007EC517 /* UIImage+AspectFit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIImage+AspectFit.swift"; path = "../../ImageSlideshow/Classes/Core/UIImage+AspectFit.swift"; sourceTree = ""; }; D0E8A9EF1D97EB94007EC517 /* UIImageView+Tools.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIImageView+Tools.swift"; path = "../../ImageSlideshow/Classes/Core/UIImageView+Tools.swift"; sourceTree = ""; }; D0E8A9F01D97EB94007EC517 /* ZoomAnimatedTransitioning.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ZoomAnimatedTransitioning.swift; path = ../../ImageSlideshow/Classes/Core/ZoomAnimatedTransitioning.swift; sourceTree = ""; }; + E6D20C7D24DD6426005CFB3C /* arrow-right-64x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "arrow-right-64x.png"; path = "../../../ImageSlideshow/Assets/arrow-right-64x.png"; sourceTree = ""; }; + E6D20C7E24DD6426005CFB3C /* arrow-left-64x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "arrow-left-64x.png"; path = "../../../ImageSlideshow/Assets/arrow-left-64x.png"; sourceTree = ""; }; F539204B210F03600057EFB3 /* SwiftSupport.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SwiftSupport.swift; path = ../../ImageSlideshow/Classes/Core/SwiftSupport.swift; sourceTree = ""; }; F802998E20CE9EA7009D64DD /* PageIndicatorPosition.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = PageIndicatorPosition.swift; path = ../../ImageSlideshow/Classes/Core/PageIndicatorPosition.swift; sourceTree = ""; }; FD45C56C18E7B8EC08371B86 /* Pods-ImageSlideshow_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ImageSlideshow_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ImageSlideshow_Example/Pods-ImageSlideshow_Example.debug.xcconfig"; sourceTree = ""; }; @@ -198,6 +202,8 @@ D00C7A2420B4C05C00E5725B /* Resources */ = { isa = PBXGroup; children = ( + E6D20C7E24DD6426005CFB3C /* arrow-left-64x.png */, + E6D20C7D24DD6426005CFB3C /* arrow-right-64x.png */, D00C7A2620B4C0A100E5725B /* ic_cross_white@2x.png */, D00C7A2520B4C0A000E5725B /* ic_cross_white@3x.png */, ); @@ -367,8 +373,10 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + E6D20C7F24DD6427005CFB3C /* arrow-right-64x.png in Resources */, D00C7A2720B4C0A100E5725B /* ic_cross_white@3x.png in Resources */, D00C7A2820B4C0A100E5725B /* ic_cross_white@2x.png in Resources */, + E6D20C8024DD6427005CFB3C /* arrow-left-64x.png in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/ImageSlideshow/Assets/arrow-left-64x.png b/ImageSlideshow/Assets/arrow-left-64x.png new file mode 100644 index 00000000..7ec5eb9b Binary files /dev/null and b/ImageSlideshow/Assets/arrow-left-64x.png differ diff --git a/ImageSlideshow/Assets/arrow-right-64x.png b/ImageSlideshow/Assets/arrow-right-64x.png new file mode 100644 index 00000000..549d6589 Binary files /dev/null and b/ImageSlideshow/Assets/arrow-right-64x.png differ diff --git a/ImageSlideshow/Classes/Core/FullScreenSlideshowViewController.swift b/ImageSlideshow/Classes/Core/FullScreenSlideshowViewController.swift index a010d421..e70ff855 100644 --- a/ImageSlideshow/Classes/Core/FullScreenSlideshowViewController.swift +++ b/ImageSlideshow/Classes/Core/FullScreenSlideshowViewController.swift @@ -13,6 +13,7 @@ open class FullScreenSlideshowViewController: UIViewController { open var slideshow: ImageSlideshow = { let slideshow = ImageSlideshow() slideshow.zoomEnabled = true + slideshow.isFullScreenSlideShow = true slideshow.contentScaleMode = UIViewContentMode.scaleAspectFit slideshow.pageIndicatorPosition = PageIndicatorPosition(horizontal: .center, vertical: .bottom) // turns off the timer @@ -21,6 +22,12 @@ open class FullScreenSlideshowViewController: UIViewController { return slideshow }() + + /// Left Arrow button + open var leftArrowButton = UIButton() + + /// Right Arrow button + open var rightArrowButton = UIButton() /// Close button open var closeButton = UIButton() @@ -47,6 +54,8 @@ open class FullScreenSlideshowViewController: UIViewController { } } + fileprivate var hideInfo = true + fileprivate var isInit = true convenience init() { @@ -70,11 +79,44 @@ open class FullScreenSlideshowViewController: UIViewController { } view.addSubview(slideshow) + + let singleTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(singleTapAction)) + singleTapGestureRecognizer.numberOfTapsRequired = 1 + slideshow.addGestureRecognizer(singleTapGestureRecognizer) + + updateUI() // close button configuration closeButton.setImage(UIImage(named: "ic_cross_white", in: Bundle(for: type(of: self)), compatibleWith: nil), for: UIControlState()) closeButton.addTarget(self, action: #selector(FullScreenSlideshowViewController.close), for: UIControlEvents.touchUpInside) view.addSubview(closeButton) + + // left arrow button configuration + leftArrowButton.setImage(UIImage(named: "arrow-left-64x", in: Bundle(for: type(of: self)), compatibleWith: nil)?.withRenderingMode(.alwaysTemplate), for: UIControlState()) + leftArrowButton.addTarget(self, action: #selector(FullScreenSlideshowViewController.leftArrowTap(_:)), for: UIControlEvents.touchUpInside) + view.addSubview(leftArrowButton) + + // Right arrow button configuration + rightArrowButton.setImage(UIImage(named: "arrow-right-64x", in: Bundle(for: type(of: self)), compatibleWith: nil)?.withRenderingMode(.alwaysTemplate), for: UIControlState()) + rightArrowButton.addTarget(self, action: #selector(FullScreenSlideshowViewController.rightArrowTap(_:)), for: UIControlEvents.touchUpInside) + view.addSubview(rightArrowButton) + leftArrowButton.translatesAutoresizingMaskIntoConstraints = false + rightArrowButton.translatesAutoresizingMaskIntoConstraints = false + leftArrowButton.backgroundColor = UIColor.black.withAlphaComponent(0.5) + rightArrowButton.backgroundColor = UIColor.black.withAlphaComponent(0.5) + leftArrowButton.tintColor = .white + rightArrowButton.tintColor = .white + + closeButton.backgroundColor = UIColor.black.withAlphaComponent(0.5) + + let leadingConstraint = NSLayoutConstraint(item: leftArrowButton, attribute: NSLayoutConstraint.Attribute.leading, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.leading, multiplier: 1, constant: 0) + let centerLeftConstraint = NSLayoutConstraint(item: leftArrowButton, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: 0) + + let trailingConstraint = NSLayoutConstraint(item: rightArrowButton, attribute: NSLayoutConstraint.Attribute.trailing, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.trailing, multiplier: 1, constant: 0) + let centerRightConstraint = NSLayoutConstraint(item: rightArrowButton, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: 0) + + + NSLayoutConstraint.activate([leadingConstraint, centerLeftConstraint, trailingConstraint, centerRightConstraint]) } override open var prefersStatusBarHidden: Bool { @@ -109,6 +151,7 @@ open class FullScreenSlideshowViewController: UIViewController { } closeButton.frame = closeButtonFrame ?? CGRect(x: max(10, safeAreaInsets.left), y: max(10, safeAreaInsets.top), width: 40, height: 40) + closeButton.layer.cornerRadius = 20 } slideshow.frame = view.frame @@ -122,4 +165,26 @@ open class FullScreenSlideshowViewController: UIViewController { dismiss(animated: true, completion: nil) } + + fileprivate func updateUI() { + closeButton.isHidden = hideInfo + rightArrowButton.isHidden = hideInfo || slideshow.slideshowItems.count < 2 + leftArrowButton.isHidden = hideInfo || slideshow.slideshowItems.count < 2 + slideshow.hideCaption = hideInfo + } + + @objc private func rightArrowTap(_ sender: UIButton) { + let nextIndex = slideshow.currentPage + 1 + slideshow.setCurrentPage(nextIndex, animated: true) + } + + @objc private func leftArrowTap(_ sender: UIButton) { + let nextIndex = slideshow.currentPage - 1 + slideshow.setCurrentPage(nextIndex, animated: true) + } + + @objc func singleTapAction() { + hideInfo = !hideInfo + updateUI() + } } diff --git a/ImageSlideshow/Classes/Core/ImageSlideshow.swift b/ImageSlideshow/Classes/Core/ImageSlideshow.swift index 9d4fbd37..bb28805f 100644 --- a/ImageSlideshow/Classes/Core/ImageSlideshow.swift +++ b/ImageSlideshow/Classes/Core/ImageSlideshow.swift @@ -164,6 +164,20 @@ open class ImageSlideshow: UIView { } } } + + /// isFullScreenSlideShow handle fullscreen + open var isFullScreenSlideShow = false { + didSet { + reloadScrollView() + } + } + + /// hide Caption handle for full screen + var hideCaption = true { + didSet { + updateCaption() + } + } /// Enables/disables user interactions open var draggingEnabled = true { @@ -320,8 +334,9 @@ open class ImageSlideshow: UIView { var i = 0 for image in scrollViewImages { - let item = ImageSlideshowItem(image: image, zoomEnabled: zoomEnabled, activityIndicator: activityIndicator?.create(), maximumScale: maximumScale) + let item = ImageSlideshowItem(image: image, zoomEnabled: zoomEnabled, activityIndicator: activityIndicator?.create(), maximumScale: maximumScale, isFullScreenSlideShow: isFullScreenSlideShow) item.imageView.contentMode = contentScaleMode + item.hideCaption = hideCaption slideshowItems.append(item) scrollView.addSubview(item) i += 1 @@ -355,6 +370,12 @@ open class ImageSlideshow: UIView { } } } + + private func updateCaption() { + for view in slideshowItems { + view.hideCaption = hideCaption + } + } // MARK: - Image setting @@ -537,18 +558,23 @@ open class ImageSlideshow: UIView { - returns: FullScreenSlideshowViewController instance */ @discardableResult - open func presentFullScreenController(from controller: UIViewController, completion: (() -> Void)? = nil) -> FullScreenSlideshowViewController { + open func presentFullScreenController(from controller: UIViewController, contentScaleMode: UIViewContentMode = UIViewContentMode.scaleAspectFill, completion: (() -> Void)? = nil) -> FullScreenSlideshowViewController { let fullscreen = FullScreenSlideshowViewController() fullscreen.pageSelected = {[weak self] (page: Int) in self?.setCurrentPage(page, animated: false) } - + let currentScaleMode = self.contentScaleMode + self.contentScaleMode = contentScaleMode + fullscreen.slideshow.contentScaleMode = contentScaleMode fullscreen.initialPage = currentPage fullscreen.inputs = images slideshowTransitioningDelegate = ZoomAnimatedTransitioningDelegate(slideshowView: self, slideshowController: fullscreen) fullscreen.transitioningDelegate = slideshowTransitioningDelegate fullscreen.modalPresentationStyle = .custom - controller.present(fullscreen, animated: true, completion: completion) + controller.present(fullscreen, animated: true) { + self.contentScaleMode = currentScaleMode + completion?() + } return fullscreen } diff --git a/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift b/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift index 7b2136a8..916c103e 100644 --- a/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift +++ b/ImageSlideshow/Classes/Core/ImageSlideshowItem.swift @@ -14,6 +14,15 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate { /// Image view to hold the image public let imageView = UIImageView() + /// Caption Label to show image caption + public let captionLabel = UILabel() + + /// Caption Container that add caption and background color + fileprivate var captionContainerView: UIView + + /// isFullScreenSlideShow ture if slider full screen controller shown + public let isFullScreenSlideShow: Bool + /// Activity indicator shown during image loading, when nil there won't be shown any public let activityIndicator: ActivityIndicatorView? @@ -31,6 +40,12 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate { /// Maximum zoom scale open var maximumScale: CGFloat = 2.0 + + var hideCaption = false { + didSet { + updateCaption() + } + } fileprivate var lastFrame = CGRect.zero fileprivate var imageReleased = false @@ -53,12 +68,25 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate { - parameter image: Input Source to load the image - parameter zoomEnabled: holds if it should be possible to zoom-in the image */ - init(image: InputSource, zoomEnabled: Bool, activityIndicator: ActivityIndicatorView? = nil, maximumScale: CGFloat = 2.0) { + init(image: InputSource, zoomEnabled: Bool, activityIndicator: ActivityIndicatorView? = nil, maximumScale: CGFloat = 2.0, isFullScreenSlideShow: Bool) { self.zoomEnabled = zoomEnabled self.image = image self.activityIndicator = activityIndicator self.maximumScale = maximumScale - + self.isFullScreenSlideShow = isFullScreenSlideShow + + let captionConstraintView = UIView() + captionConstraintView.addSubview(captionLabel) + if #available(iOS 9.0, *) { + let captionStackView = UIStackView() + captionStackView.axis = .vertical + captionStackView.alignment = .leading + captionStackView.addArrangedSubview(captionConstraintView) + captionContainerView = captionStackView + } else { + captionContainerView = captionConstraintView + } + super.init(frame: CGRect.null) imageViewWrapper.addSubview(imageView) @@ -99,6 +127,22 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate { singleTapGestureRecognizer!.numberOfTapsRequired = 1 singleTapGestureRecognizer!.isEnabled = false imageViewWrapper.addGestureRecognizer(singleTapGestureRecognizer!) + + captionContainerView.addSubview(captionConstraintView) + imageViewWrapper.addSubview(captionContainerView) + captionLabel.textColor = .white + captionLabel.numberOfLines = 0 + captionConstraintView.backgroundColor = UIColor.black.withAlphaComponent(0.5) + captionLabel.translatesAutoresizingMaskIntoConstraints = false + captionContainerView.translatesAutoresizingMaskIntoConstraints = false + + let leadingConstraint = NSLayoutConstraint(item: captionLabel, attribute: NSLayoutConstraint.Attribute.leading, relatedBy: NSLayoutConstraint.Relation.equal, toItem: captionConstraintView, attribute: NSLayoutConstraint.Attribute.leading, multiplier: 1, constant: 5) + let trailingConstraint = NSLayoutConstraint(item: captionLabel, attribute: NSLayoutConstraint.Attribute.trailing, relatedBy: NSLayoutConstraint.Relation.equal, toItem: captionConstraintView, attribute: NSLayoutConstraint.Attribute.trailing, multiplier: 1, constant: -5) + let topConstraint = NSLayoutConstraint(item: captionLabel, attribute: NSLayoutConstraint.Attribute.top, relatedBy: NSLayoutConstraint.Relation.equal, toItem: captionConstraintView, attribute: NSLayoutConstraint.Attribute.top, multiplier: 1, constant: 5) + let bottomConstraint = NSLayoutConstraint(item: captionLabel, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: captionConstraintView, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: -5) + + NSLayoutConstraint.activate([topConstraint, leadingConstraint, bottomConstraint, trailingConstraint,]) + } required public init?(coder aDecoder: NSCoder) { @@ -131,6 +175,10 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate { contentSize = imageViewWrapper.frame.size maximumZoomScale = calculateMaximumScale() + + let leadingConstraint = NSLayoutConstraint(item: captionContainerView, attribute: NSLayoutConstraint.Attribute.leading, relatedBy: NSLayoutConstraint.Relation.equal, toItem: imageViewWrapper, attribute: NSLayoutConstraint.Attribute.leading, multiplier: 1, constant: 20) + let trailingConstraint = NSLayoutConstraint(item: captionContainerView, attribute: NSLayoutConstraint.Attribute.trailing, relatedBy: NSLayoutConstraint.Relation.equal, toItem: imageViewWrapper, attribute: NSLayoutConstraint.Attribute.trailing, multiplier: 1, constant: -20) + NSLayoutConstraint.activate([leadingConstraint, trailingConstraint,]) } /// Request to load Image Source to Image View @@ -139,18 +187,24 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate { isLoading = true imageReleased = false activityIndicator?.show() - image.load(to: self.imageView) {[weak self] image in + image.load(to: self.imageView) {[weak self] (image, caption, captionBottomConstraint, showCaptionOnlyInFullScreen) in + guard let self = self else { return } // set image to nil if there was a release request during the image load - if let imageRelease = self?.imageReleased, imageRelease { - self?.imageView.image = nil + if self.imageReleased { + self.imageView.image = nil } else { - self?.imageView.image = image + self.imageView.image = image } - self?.activityIndicator?.hide() - self?.loadFailed = image == nil - self?.isLoading = false + self.captionLabel.text = caption + self.captionContainerView.isHidden = self.hideCaption || (!self.isFullScreenSlideShow && showCaptionOnlyInFullScreen) || (caption ?? "").isEmpty - self?.setNeedsLayout() + NSLayoutConstraint(item: self.captionContainerView, attribute: NSLayoutConstraint.Attribute.bottom, relatedBy: NSLayoutConstraint.Relation.equal, toItem: self.imageViewWrapper, attribute: NSLayoutConstraint.Attribute.bottom, multiplier: 1, constant: captionBottomConstraint).isActive = true + + self.activityIndicator?.hide() + self.loadFailed = image == nil + self.isLoading = false + + self.setNeedsLayout() } } } @@ -169,6 +223,11 @@ open class ImageSlideshowItem: UIScrollView, UIScrollViewDelegate { self.loadImage() } + + private func updateCaption() { + self.captionContainerView.isHidden = self.hideCaption || (captionLabel.text ?? "").isEmpty + } + // MARK: - Image zoom & size func isZoomed() -> Bool { diff --git a/ImageSlideshow/Classes/Core/InputSource.swift b/ImageSlideshow/Classes/Core/InputSource.swift index 3689af2a..f787fee1 100644 --- a/ImageSlideshow/Classes/Core/InputSource.swift +++ b/ImageSlideshow/Classes/Core/InputSource.swift @@ -16,7 +16,7 @@ import UIKit - parameter callback: Callback called after image was set to the image view. - parameter image: Image that was set to the image view. */ - func load(to imageView: UIImageView, with callback: @escaping (_ image: UIImage?) -> Void) + func load(to imageView: UIImageView, with callback: @escaping (_ image: UIImage?, _ caption: String?, _ captionBottomConstraint: CGFloat, _ showCaptionOnlyInFullScreen: Bool) -> Void) /** Cancel image load on the image view @@ -29,28 +29,37 @@ import UIKit @objcMembers open class ImageSource: NSObject, InputSource { var image: UIImage + var caption: String + var captionBottomConstraint: CGFloat + var showCaptionOnlyInFullScreen: Bool /// Initializes a new Image Source with UIImage /// - parameter image: Image to be loaded - public init(image: UIImage) { + public init(image: UIImage, caption: String = "", captionBottomConstraint: CGFloat = 0, showCaptionOnlyInFullScreen: Bool = false) { self.image = image + self.caption = caption + self.captionBottomConstraint = captionBottomConstraint + self.showCaptionOnlyInFullScreen = showCaptionOnlyInFullScreen } /// Initializes a new Image Source with an image name from the main bundle /// - parameter imageString: name of the file in the application's main bundle @available(*, deprecated, message: "Use `BundleImageSource` instead") - public init?(imageString: String) { + public init?(imageString: String, caption: String = "", captionBottomConstraint: CGFloat = 0, showCaptionOnlyInFullScreen: Bool = false) { if let image = UIImage(named: imageString) { self.image = image + self.caption = caption + self.captionBottomConstraint = captionBottomConstraint + self.showCaptionOnlyInFullScreen = showCaptionOnlyInFullScreen super.init() } else { return nil } } - public func load(to imageView: UIImageView, with callback: @escaping (UIImage?) -> Void) { + public func load(to imageView: UIImageView, with callback: @escaping (UIImage?, String?, CGFloat, Bool) -> Void) { imageView.image = image - callback(image) + callback(image, caption, captionBottomConstraint, showCaptionOnlyInFullScreen) } } @@ -58,18 +67,25 @@ open class ImageSource: NSObject, InputSource { @objcMembers open class BundleImageSource: NSObject, InputSource { var imageString: String + var caption: String + var captionBottomConstraint: CGFloat + var showCaptionOnlyInFullScreen: Bool /// Initializes a new Image Source with an image name from the main bundle /// - parameter imageString: name of the file in the application's main bundle - public init(imageString: String) { + public init(imageString: String, caption: String = "", captionBottomConstraint: CGFloat = 0, showCaptionOnlyInFullScreen: Bool = false) { self.imageString = imageString + self.caption = caption + self.captionBottomConstraint = captionBottomConstraint + self.showCaptionOnlyInFullScreen = showCaptionOnlyInFullScreen + super.init() } - public func load(to imageView: UIImageView, with callback: @escaping (UIImage?) -> Void) { + public func load(to imageView: UIImageView, with callback: @escaping (UIImage?, String?, CGFloat, Bool) -> Void) { let image = UIImage(named: imageString) imageView.image = image - callback(image) + callback(image, caption, captionBottomConstraint, showCaptionOnlyInFullScreen) } } @@ -77,17 +93,24 @@ open class BundleImageSource: NSObject, InputSource { @objcMembers open class FileImageSource: NSObject, InputSource { var path: String + var caption: String + var captionBottomConstraint: CGFloat + var showCaptionOnlyInFullScreen: Bool /// Initializes a new Image Source with an image name from the main bundle /// - parameter imageString: name of the file in the application's main bundle - public init(path: String) { + public init(path: String, caption: String = "", captionBottomConstraint: CGFloat = 0, showCaptionOnlyInFullScreen: Bool = false) { self.path = path + self.caption = caption + self.captionBottomConstraint = captionBottomConstraint + self.showCaptionOnlyInFullScreen = showCaptionOnlyInFullScreen + super.init() } - public func load(to imageView: UIImageView, with callback: @escaping (UIImage?) -> Void) { + public func load(to imageView: UIImageView, with callback: @escaping (UIImage?, String?, CGFloat, Bool) -> Void) { let image = UIImage(contentsOfFile: path) imageView.image = image - callback(image) + callback(image, caption, captionBottomConstraint, showCaptionOnlyInFullScreen) } } diff --git a/ImageSlideshow/Classes/Core/ZoomAnimatedTransitioning.swift b/ImageSlideshow/Classes/Core/ZoomAnimatedTransitioning.swift index 9b29afae..f8277b07 100644 --- a/ImageSlideshow/Classes/Core/ZoomAnimatedTransitioning.swift +++ b/ImageSlideshow/Classes/Core/ZoomAnimatedTransitioning.swift @@ -224,7 +224,7 @@ class ZoomInAnimator: ZoomAnimator, UIViewControllerAnimatedTransitioning { referenceImageView.alpha = 0 - if let image = referenceImageView.image { + if let image = referenceImageView.image, referenceImageView.contentMode == .scaleAspectFit { transitionViewFinalFrame = image.tgr_aspectFitRectForSize(finalFrame.size) } }