master b6f11ca2a2fe cached
22 files
76.6 KB
20.8k tokens
1 requests
Download .txt
Repository: pigfly/A_J_Full_Screen_Image_Browser
Branch: master
Commit: b6f11ca2a2fe
Files: 22
Total size: 76.6 KB

Directory structure:
gitextract_g2d1cdig/

├── .gitignore
├── A_J_Full_Screen_Image_Browser/
│   ├── AppDelegate.swift
│   ├── Assets.xcassets/
│   │   └── AppIcon.appiconset/
│   │       └── Contents.json
│   ├── Base.lproj/
│   │   ├── LaunchScreen.storyboard
│   │   └── Main.storyboard
│   ├── Info.plist
│   ├── ViewController.swift
│   ├── animator/
│   │   └── FullScreenImageTransitionAnimator.swift
│   ├── core/
│   │   ├── FullScreenImageBrowser.swift
│   │   ├── FullScreenImageBrowserViewModel.swift
│   │   ├── MaskImageViewer.swift
│   │   ├── MediaDownloadable.swift
│   │   ├── SingleImageViewer.swift
│   │   └── ZoomableImageView.swift
│   └── helper/
│       ├── SingleMedia.swift
│       ├── UIImage+Ex.swift
│       └── UIView+SnapShot.swift
├── A_J_Full_Screen_Image_Browser.xcodeproj/
│   ├── project.pbxproj
│   └── project.xcworkspace/
│       ├── contents.xcworkspacedata
│       └── xcshareddata/
│           └── IDEWorkspaceChecks.plist
├── LICENSE
└── README.md

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3


================================================
FILE: A_J_Full_Screen_Image_Browser/AppDelegate.swift
================================================
//
//  AppDelegate.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Junliang Jiang on 25/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}



================================================
FILE: A_J_Full_Screen_Image_Browser/Assets.xcassets/AppIcon.appiconset/Contents.json
================================================
{
  "images" : [
    {
      "idiom" : "iphone",
      "size" : "20x20",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "20x20",
      "scale" : "3x"
    },
    {
      "idiom" : "iphone",
      "size" : "29x29",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "29x29",
      "scale" : "3x"
    },
    {
      "idiom" : "iphone",
      "size" : "40x40",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "40x40",
      "scale" : "3x"
    },
    {
      "idiom" : "iphone",
      "size" : "60x60",
      "scale" : "2x"
    },
    {
      "idiom" : "iphone",
      "size" : "60x60",
      "scale" : "3x"
    },
    {
      "idiom" : "ipad",
      "size" : "20x20",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "20x20",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "29x29",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "29x29",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "40x40",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "40x40",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "76x76",
      "scale" : "1x"
    },
    {
      "idiom" : "ipad",
      "size" : "76x76",
      "scale" : "2x"
    },
    {
      "idiom" : "ipad",
      "size" : "83.5x83.5",
      "scale" : "2x"
    }
  ],
  "info" : {
    "version" : 1,
    "author" : "xcode"
  }
}

================================================
FILE: A_J_Full_Screen_Image_Browser/Base.lproj/LaunchScreen.storyboard
================================================
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" systemVersion="17A277" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
    <dependencies>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="EHf-IW-A2E">
            <objects>
                <viewController id="01J-lp-oVM" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                        <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="53" y="375"/>
        </scene>
    </scenes>
</document>


================================================
FILE: A_J_Full_Screen_Image_Browser/Base.lproj/Main.storyboard
================================================
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
    <device id="retina4_7" orientation="portrait">
        <adaptation id="fullscreen"/>
    </device>
    <dependencies>
        <deployment identifier="iOS"/>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13527"/>
        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="tne-QT-ifu">
            <objects>
                <viewController id="BYZ-38-t0r" customClass="ViewController" customModule="A_J_Full_Screen_Image_Browser" customModuleProvider="target" sceneMemberID="viewController">
                    <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
                        <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4Se-Fg-AJ1">
                                <rect key="frame" x="167" y="318" width="40" height="30"/>
                                <state key="normal" title="boom"/>
                                <connections>
                                    <action selector="onButtonTapped:" destination="BYZ-38-t0r" eventType="touchUpInside" id="cU7-4k-oyE"/>
                                </connections>
                            </button>
                        </subviews>
                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                        <constraints>
                            <constraint firstItem="4Se-Fg-AJ1" firstAttribute="centerY" secondItem="8bC-Xf-vdC" secondAttribute="centerY" id="4wX-6a-B2q"/>
                            <constraint firstItem="4Se-Fg-AJ1" firstAttribute="centerX" secondItem="8bC-Xf-vdC" secondAttribute="centerX" id="B2z-ho-Efc"/>
                        </constraints>
                        <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
            </objects>
        </scene>
    </scenes>
</document>


================================================
FILE: A_J_Full_Screen_Image_Browser/Info.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>$(DEVELOPMENT_LANGUAGE)</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleVersion</key>
	<string>1</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>NSAppTransportSecurity</key>
	<dict>
		<key>NSAllowsArbitraryLoads</key>
		<true/>
	</dict>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIMainStoryboardFile</key>
	<string>Main</string>
	<key>UIRequiredDeviceCapabilities</key>
	<array>
		<string>armv7</string>
	</array>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
</dict>
</plist>


================================================
FILE: A_J_Full_Screen_Image_Browser/ViewController.swift
================================================
//
//  ViewController.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Junliang Jiang on 25/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

final class ViewController: UIViewController {

    lazy var testVideo: MediaDownloadable = {
        return SingleMedia(imageURL: URL(string: "https://dummyimage.com/600&text=thumbnail")!,
                    isVideoThumbnail: true,
                    videoURL: URL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!)
    }()

    lazy var media: [MediaDownloadable] = {
        return [testVideo,
                SingleMedia(imageURL: URL(string: "https://dummyimage.com/300")!),
                SingleMedia(imageURL: URL(string: "https://dummyimage.com/600")!),
                testVideo]
    }()

    @IBAction func onButtonTapped(_ sender: UIButton) {
        let vm = FullScreenImageBrowserViewModel(media: media)
        let x = FullScreenImageBrowser(viewModel: vm)
        present(x, animated: true, completion: nil)
    }

}



================================================
FILE: A_J_Full_Screen_Image_Browser/animator/FullScreenImageTransitionAnimator.swift
================================================
//
//  TransitionAnimator.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Junliang Jiang on 25/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

public final class FullScreenImageTransitionAnimator: NSObject, UIViewControllerAnimatedTransitioning {
    var dismissing: Bool = false

    var startingView: UIView?
    var endingView: UIView?

    var startingViewForAnimation: UIView?
    var endingViewForAnimation: UIView?

    var animationDurationWithZooming = 0.5
    var animationDurationWithoutZooming = 0.3
    var animationDurationFadeRatio = 4.0 / 9.0 {
        didSet(value) {
            animationDurationFadeRatio = min(value, 1.0)
        }
    }
    var animationDurationEndingViewFadeInRatio = 0.1 {
        didSet(value) {
            animationDurationEndingViewFadeInRatio = min(value, 1.0)
        }
    }
    var animationDurationStartingViewFadeOutRatio = 0.05 {
        didSet(value) {
            animationDurationStartingViewFadeOutRatio = min(value, 1.0)
        }
    }
    var zoomingAnimationSpringDamping = 0.9

    var shouldPerformZoomingAnimation: Bool {
        return startingView != nil && endingView != nil
    }

    public func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        if shouldPerformZoomingAnimation {
            return animationDurationWithZooming
        }
        return animationDurationWithoutZooming
    }

    func fadeDurationForTransitionContext(_ transitionContext: UIViewControllerContextTransitioning) -> TimeInterval {
        if shouldPerformZoomingAnimation {
            return transitionDuration(using: transitionContext) * animationDurationFadeRatio
        }
        return transitionDuration(using: transitionContext)
    }

    // MARK: - UIViewControllerAnimatedTransitioning
    public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        setupTransitionContainerHierarchyWithTransitionContext(transitionContext)

        if shouldPerformZoomingAnimation {
            performZoomingAnimationWithTransitionContext(transitionContext)
        }
        performFadeAnimationWithTransitionContext(transitionContext)
    }

    func setupTransitionContainerHierarchyWithTransitionContext(_ transitionContext: UIViewControllerContextTransitioning) {

        if let toView = transitionContext.view(forKey: UITransitionContextViewKey.to),
            let toViewController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) {
            toView.frame = transitionContext.finalFrame(for: toViewController)
            let containerView = transitionContext.containerView

            if !toView.isDescendant(of: containerView) {
                containerView.addSubview(toView)
            }
        }

        if dismissing {
            if let fromView = transitionContext.view(forKey: UITransitionContextViewKey.from) {
                transitionContext.containerView.bringSubview(toFront: fromView)
            }
        }
    }

    func performFadeAnimationWithTransitionContext(_ transitionContext: UIViewControllerContextTransitioning) {
        let fadeView = dismissing ? transitionContext.view(forKey: UITransitionContextViewKey.from) : transitionContext.view(forKey: UITransitionContextViewKey.to)
        let beginningAlpha: CGFloat = dismissing ? 1.0 : 0.0
        let endingAlpha: CGFloat = dismissing ? 0.0 : 1.0

        fadeView?.alpha = beginningAlpha

        UIView.animate(withDuration: fadeDurationForTransitionContext(transitionContext), animations: { () -> Void in
            fadeView?.alpha = endingAlpha
        }) { _ in
            if !self.shouldPerformZoomingAnimation {
                self.completeTransitionWithTransitionContext(transitionContext)
            }
        }
    }

    func performZoomingAnimationWithTransitionContext(_ transitionContext: UIViewControllerContextTransitioning) {

        let containerView = transitionContext.containerView
        guard let startingView = startingView, let endingView = endingView else {
            return
        }
        guard let startingViewForAnimation = self.startingViewForAnimation ?? self.startingView?.aj_snapshotView(),
            let endingViewForAnimation = self.endingViewForAnimation ?? self.endingView?.aj_snapshotView() else {
                return
        }

        let finalEndingViewTransform = endingView.transform
        let endingViewInitialTransform = startingViewForAnimation.frame.height / endingViewForAnimation.frame.height
        let translatedStartingViewCenter = startingView.aj_translatedCenterPointToContainerView(containerView)

        startingViewForAnimation.center = translatedStartingViewCenter

        endingViewForAnimation.transform = endingViewForAnimation.transform.scaledBy(x: endingViewInitialTransform, y: endingViewInitialTransform)
        endingViewForAnimation.center = translatedStartingViewCenter
        endingViewForAnimation.alpha = 0.0

        containerView.addSubview(startingViewForAnimation)
        containerView.addSubview(endingViewForAnimation)

        endingView.alpha = 0.0
        startingView.alpha = 0.0

        let fadeInDuration = transitionDuration(using: transitionContext) * animationDurationEndingViewFadeInRatio
        let fadeOutDuration = transitionDuration(using: transitionContext) * animationDurationStartingViewFadeOutRatio

        UIView.animate(withDuration: fadeInDuration, delay: 0.0, options: [.allowAnimatedContent, .beginFromCurrentState], animations: { () -> Void in
            endingViewForAnimation.alpha = 1.0
        }) { _ in
            UIView.animate(withDuration: fadeOutDuration, delay: 0.0, options: [.allowAnimatedContent, .beginFromCurrentState], animations: { () -> Void in
                startingViewForAnimation.alpha = 0.0
            }, completion: { _ in
                startingViewForAnimation.removeFromSuperview()
            })
        }

        let startingViewFinalTransform = 1.0 / endingViewInitialTransform
        let translatedEndingViewFinalCenter = endingView.aj_translatedCenterPointToContainerView(containerView)

        UIView.animate(withDuration: transitionDuration(using: transitionContext), delay: 0.0, usingSpringWithDamping:CGFloat(zoomingAnimationSpringDamping), initialSpringVelocity:0, options: [.allowAnimatedContent, .beginFromCurrentState], animations: { () -> Void in
            endingViewForAnimation.transform = finalEndingViewTransform
            endingViewForAnimation.center = translatedEndingViewFinalCenter
            startingViewForAnimation.transform = startingViewForAnimation.transform.scaledBy(x: startingViewFinalTransform, y: startingViewFinalTransform)
            startingViewForAnimation.center = translatedEndingViewFinalCenter

        }) { _ in
            endingViewForAnimation.removeFromSuperview()
            endingView.alpha = 1.0
            startingView.alpha = 1.0
            self.completeTransitionWithTransitionContext(transitionContext)
        }
    }

    func completeTransitionWithTransitionContext(_ transitionContext: UIViewControllerContextTransitioning) {
        if transitionContext.isInteractive {
            if transitionContext.transitionWasCancelled {
                transitionContext.cancelInteractiveTransition()
            } else {
                transitionContext.finishInteractiveTransition()
            }
        }
        transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
    }
}


================================================
FILE: A_J_Full_Screen_Image_Browser/core/FullScreenImageBrowser.swift
================================================
//
//  FullScreenImageBrowser.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Junliang Jiang on 25/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit
import AVKit

public final class FullScreenImageBrowser: UIViewController {

    // MARK: - Property
    public var viewModel: FullScreenImageBrowserViewModel
    public private(set) var pageViewController: UIPageViewController
    public let transitionAnimator: FullScreenImageTransitionAnimator = FullScreenImageTransitionAnimator()

    public private(set) lazy var singleTapGestureRecognizer: UITapGestureRecognizer = {
        return UITapGestureRecognizer(target: self, action: #selector(FullScreenImageBrowser.handleSingleTapGestureRecognizer(_:)))
    }()
    public private(set) lazy var panGestureRecognizer: UIPanGestureRecognizer = {
        return UIPanGestureRecognizer(target: self, action: #selector(FullScreenImageBrowser.handlePanGestureRecognizer(_:)))
    }()
    
    /*
     * The mask view displayed over images
     */
    public var maskView: MaskImageView = MaskImageView(frame: .zero) {
        willSet {
            maskView.removeFromSuperview()
        }
        didSet {
            maskView.imagesBrowser = self
            maskView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
            maskView.frame = view.bounds
            view.addSubview(maskView)
        }
    }

    public var currentMedia: MediaDownloadable? {
        return currentImageViewer?.media
    }

    private var statusBarHidden = false

    // MARK: - Init
    required public init?(coder aDecoder: NSCoder) {
        viewModel = FullScreenImageBrowserViewModel(media: [])
        pageViewController = UIPageViewController()
        super.init(nibName: nil, bundle: nil)
        initialSetupWithImage(nil)
    }

    public override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: Bundle!) {
        viewModel = FullScreenImageBrowserViewModel(media: [])
        pageViewController = UIPageViewController()
        super.init(nibName: nil, bundle: nil)
        initialSetupWithImage(nil)
    }

    /**
     The designated initializer

     - parameter viewModel:     View model instance for Full Screen Image Browser.
     - parameter startingImage: The image to be displayed at first place when launching image browser.
     - parameter referenceView: The view from which to animate.

     - returns: an instance of full screen image browser
     */
    public required init(viewModel: FullScreenImageBrowserViewModel,
                startingImage: MediaDownloadable? = nil,
                referenceView: UIView? = nil) {
        self.viewModel = viewModel
        pageViewController = UIPageViewController()
        super.init(nibName: nil, bundle: nil)

        initialSetupWithImage(startingImage == nil ? viewModel.media.first : startingImage)
        transitionAnimator.startingView = referenceView
        transitionAnimator.endingView = currentImageViewer?.zoomableImageview.imageView
    }

    private func initialSetupWithImage(_ image: MediaDownloadable? = nil) {
        maskView.imagesBrowser = self
        setupPageViewControllerWith(image)

        modalPresentationStyle = .custom
        transitioningDelegate = self
        modalPresentationCapturesStatusBarAppearance = true

        let textColor = view.tintColor ?? UIColor.white
        #if swift(>=4.0)
            maskView.titleTextAttributes = [NSAttributedStringKey.foregroundColor: textColor]
        #else
            maskView.titleTextAttributes = [NSForegroundColorAttributeName: textColor]
        #endif
    }

    private func setupPageViewControllerWith(_ image: MediaDownloadable? = nil) {
        pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal, options: [UIPageViewControllerOptionInterPageSpacingKey: 16.0])
        pageViewController.view.backgroundColor = .clear
        pageViewController.delegate = self
        pageViewController.dataSource = self

        if let _image = image, viewModel.containsMedia(_image) {
            changeToImage(_image, animated: false)
        } else if let _image = viewModel.media.first {
            changeToImage(_image, animated: false)
        }
    }

    private func setupMaskView() {
        maskView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        maskView.frame = view.bounds
        view.addSubview(maskView)
        maskView.setHidden(true, animated: false)
    }

    deinit {
        pageViewController.delegate = nil
        pageViewController.dataSource = nil
    }

    // MARK: - View Controller Life Cycle
    override public func viewDidLoad() {
        super.viewDidLoad()
        view.tintColor = .white
        view.backgroundColor = .black
        pageViewController.view.backgroundColor = .clear

        pageViewController.view.addGestureRecognizer(panGestureRecognizer)
        pageViewController.view.addGestureRecognizer(singleTapGestureRecognizer)

        addChildViewController(pageViewController)
        view.addSubview(pageViewController.view)
        pageViewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        pageViewController.didMove(toParentViewController: self)

        setupMaskView()
    }

    override public func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)

        // This fix issue that navigationBar animate to up
        // when presentingViewController is UINavigationViewController
        statusBarHidden = true
        UIView.animate(withDuration: 0.25) { self.setNeedsStatusBarAppearanceUpdate() }
        updateCurrentImageInfo()
    }

    // MARK: - Public

    /**
     Displays the specified image. Can be called before the view controller is displayed.

     - parameter media:    The photo to make the currently displayed photo.
     - parameter animated: Whether to animate the transition to the new photo.
     */
    public func changeToImage(_ media: MediaDownloadable,
                              animated: Bool,
                              direction: UIPageViewControllerNavigationDirection = .forward) {
        if !viewModel.containsMedia(media) { return }

        let imageViewer = SingleMediaViewerFor(media)
        pageViewController.setViewControllers([imageViewer], direction: direction, animated: animated, completion: nil)
        updateCurrentImageInfo()
    }

    private func updateCurrentImageInfo() {
        if let _currentImage = currentMedia {
            maskView.populateWithImage(_currentImage)
        }
    }
}

// MARK: - UIPageViewController DataSource Delegate
extension FullScreenImageBrowser: UIPageViewControllerDataSource, UIPageViewControllerDelegate {

    /*
     * Currently displayed by page view controller
     */
    public var currentImageViewer: SingleMediaViewer? {
        return pageViewController.viewControllers?.first as? SingleMediaViewer
    }

    public func SingleMediaViewerFor(_ media: MediaDownloadable) -> SingleMediaViewer {
        let imageViewer = SingleMediaViewer(media: media)
        singleTapGestureRecognizer.require(toFail: imageViewer.doubleTapGestureRecognizer)

        return imageViewer
    }

    @objc public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
        guard let imageViewer = viewController as? SingleMediaViewer,
            let index = viewModel.indexOfMedia(imageViewer.media),
            let newImage = viewModel.mediaAtIndex(index - 1) else {
                return nil
        }
        return SingleMediaViewerFor(newImage)
    }

    @objc public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
        guard let imageViewer = viewController as? SingleMediaViewer,
            let index = viewModel.indexOfMedia(imageViewer.media),
            let newImage = viewModel.mediaAtIndex(index + 1) else {
                return nil
        }
        return SingleMediaViewerFor(newImage)
    }

    @objc public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
        if completed {
            updateCurrentImageInfo()
        }
    }
}

// MARK: - UIViewController Transitioning Delegate
extension FullScreenImageBrowser: UIViewControllerTransitioningDelegate {
    public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        transitionAnimator.dismissing = false
        return transitionAnimator
    }

    public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        transitionAnimator.dismissing = true
        return transitionAnimator
    }
}

// MARK: - Gesture Recognizer
extension FullScreenImageBrowser {
    @objc private func handleSingleTapGestureRecognizer(_ gestureRecognizer: UITapGestureRecognizer) {
        maskView.setHidden(!maskView.isHidden, animated: true)

        guard let currentMedia = currentMedia, currentMedia.isVideoThumbnail == true else { return }
        playVideo()
    }

    @objc private func handlePanGestureRecognizer(_ gestureRecognizer: UIPanGestureRecognizer) {
        dismiss(animated: true, completion: nil)
    }
}

// MARK: - Status Bar
extension FullScreenImageBrowser {
    public override var prefersStatusBarHidden: Bool {
        if let parentStatusBarHidden = presentingViewController?.prefersStatusBarHidden , parentStatusBarHidden == true {
            return parentStatusBarHidden
        }
        return statusBarHidden
    }

    public override var preferredStatusBarStyle: UIStatusBarStyle {
        return .default
    }

    public override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
        return .fade
    }
}

// MARK: - Video Showcase
extension FullScreenImageBrowser {
    public func playVideo() {
        guard let currentMedia = currentMedia else { return }
        guard let videoURL = currentMedia.videoURL else { debugPrint("\(#file) invalid url found for video"); return }
        let player = AVPlayer(url: videoURL)
        let playerController = AVPlayerViewController()
        playerController.player = player
        present(playerController, animated: true, completion: nil)
    }
}


================================================
FILE: A_J_Full_Screen_Image_Browser/core/FullScreenImageBrowserViewModel.swift
================================================
//
//  FullScreenImageBrowserViewModel.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Alex Jiang on 26/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import Foundation

public struct FullScreenImageBrowserViewModel {

    /// Designated Init
    ///
    /// - Parameter media: a collection of media to be either video or image
    public init(media: [MediaDownloadable]) {
        self.media = media
    }

    public private(set) var media: [MediaDownloadable]

    // MARK: - Media

    public var numberOfImages: Int {
        return media.count
    }

    public func mediaAtIndex(_ index: Int) -> MediaDownloadable? {
        if (index < media.count && index >= 0) {
            return media[index]
        }
        return nil
    }

    public func indexOfMedia(_ media: MediaDownloadable) -> Int? {
        return self.media.index(where: { $0 === media })
    }

    public func containsMedia(_ media: MediaDownloadable) -> Bool {
        return indexOfMedia(media) != nil
    }

    // MARK: - Video

    public var shouldShowVideo: Bool {
        return media.contains { $0.isVideoThumbnail == true }
    }

    public func videoURLAtIndex(_ index: Int) -> URL? {
        guard index < media.count && index > 0 else { return nil }
        guard let videoURL = media[index].videoURL else { return nil }

        return videoURL
    }
}


================================================
FILE: A_J_Full_Screen_Image_Browser/core/MaskImageViewer.swift
================================================
//
//  MaskImageViewer.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Junliang Jiang on 25/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

public protocol MaskImageViewable: class {
    var imagesBrowser: FullScreenImageBrowser? { get set }

    func populateWithImage(_ image: MediaDownloadable)
    func setHidden(_ hidden: Bool, animated: Bool)
}

public final class MaskImageView: UIView , MaskImageViewable {
    public private(set) var navigationBar: UINavigationBar!

    public private(set) var navigationItem: UINavigationItem!
    public weak var imagesBrowser: FullScreenImageBrowser?
    private var currentMedia: MediaDownloadable?

    public var leftBarButtonItem: UIBarButtonItem? {
        didSet {
            navigationItem.leftBarButtonItem = leftBarButtonItem
        }
    }

    #if swift(>=4.0)
    public var titleTextAttributes: [NSAttributedStringKey : AnyObject] = [:] {
        didSet {
            navigationBar.titleTextAttributes = titleTextAttributes
        }
    }
    #else
    public var titleTextAttributes: [String : AnyObject] = [:] {
        didSet {
            navigationBar.titleTextAttributes = titleTextAttributes
        }
    }
    #endif

    public override init(frame: CGRect) {
        super.init(frame: frame)
        setupNavigationBar()
    }

    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    public override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? {
        if let hitView = super.hitTest(point, with: event) , hitView != self {
            return hitView
        }
        return nil
    }

    public override func layoutSubviews() {
        UIView.performWithoutAnimation {
            self.navigationBar.invalidateIntrinsicContentSize()
            self.navigationBar.layoutIfNeeded()
        }
        super.layoutSubviews()
    }

    public func setHidden(_ hidden: Bool, animated: Bool) {
        if isHidden == hidden { return }
        if !animated { isHidden = hidden; return }

        isHidden = false
        alpha = hidden ? 1.0 : 0.0

        UIView.animate(withDuration: 0.2,
                       delay: 0.0,
                       options: [.allowAnimatedContent, .allowUserInteraction],
                       animations: { self.alpha = hidden ? 0.0 : 1.0 },
                       completion: { _ in self.alpha = 1.0; self.isHidden = hidden })
    }

    public func populateWithImage(_ media: MediaDownloadable) {
        currentMedia = media

        guard let _imagesBrowser = imagesBrowser,
              let index = imagesBrowser?.viewModel.indexOfMedia(media) else { return }

        navigationItem.title = String(format:NSLocalizedString("%d of %d",comment:""),
                                      index+1,
                                      _imagesBrowser.viewModel.numberOfImages)
    }

    @objc private func closeButtonTapped(_ sender: UIBarButtonItem) {
        imagesBrowser?.dismiss(animated: true, completion: nil)
    }

    private func setupNavigationBar() {
        navigationBar = UINavigationBar()
        navigationBar.translatesAutoresizingMaskIntoConstraints = false
        navigationBar.backgroundColor = UIColor.clear
        navigationBar.barTintColor = nil
        navigationBar.isTranslucent = true
        navigationBar.shadowImage = UIImage()
        navigationBar.setBackgroundImage(UIImage(), for: .default)

        navigationItem = UINavigationItem(title: "")
        navigationBar.items = [navigationItem]
        addSubview(navigationBar)

        let topConstraint: NSLayoutConstraint
        if #available(iOS 11.0, *) {
            topConstraint = navigationBar.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor)
        } else {
            topConstraint = navigationBar.topAnchor.constraint(equalTo: self.topAnchor)
        }
        let widthConstraint = navigationBar.widthAnchor.constraint(equalTo: self.widthAnchor)
        let horizontalConstraint = navigationBar.centerXAnchor.constraint(equalTo: self.centerXAnchor)
        NSLayoutConstraint.activate([topConstraint, widthConstraint, horizontalConstraint])

        if let bundlePath = Bundle(for: type(of: self)).path(forResource: "FullScreenImageBrowser", ofType: "bundle") {
            let bundle = Bundle(path: bundlePath)
            leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "close", in: bundle, compatibleWith: nil),
                                                style: .plain,
                                                target: self,
                                                action: #selector(MaskImageView.closeButtonTapped(_:)))
        } else {
            leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel,
                                                target: self,
                                                action: #selector(MaskImageView.closeButtonTapped(_:)))
        }
    }
}


================================================
FILE: A_J_Full_Screen_Image_Browser/core/MediaDownloadable.swift
================================================
//
//  MediaDownloadable.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Junliang Jiang on 25/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

/// Media Type protocol for defining media to be either image, or video
public protocol MediaDownloadable: class {
    var image: UIImage? { get }
    var imageURL: URL? { get }
    var isVideoThumbnail: Bool { get set }
    var videoURL: URL? { get }
    
    func loadImageWithCompletionHandler(_ completion: @escaping (_ image: UIImage?, _ error: NSError?) -> ())
}


================================================
FILE: A_J_Full_Screen_Image_Browser/core/SingleImageViewer.swift
================================================
//
//  SingleMediaViewer.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Junliang Jiang on 25/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

public final class SingleMediaViewer: UIViewController, UIScrollViewDelegate {

    // MARK: - Property
    public var media: MediaDownloadable

    public lazy private(set) var zoomableImageview: ZoomableImageView = {
        return ZoomableImageView()
    }()

    public lazy private(set) var doubleTapGestureRecognizer: UITapGestureRecognizer = {
        let gesture = UITapGestureRecognizer(target: self, action: #selector(SingleMediaViewer.handleDoubleTapWithGestureRecognizer(_:)))
        gesture.numberOfTapsRequired = 2
        return gesture
    }()

    public lazy private(set) var activityIndicator: UIActivityIndicatorView = {
        let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .white)
        activityIndicator.startAnimating()
        return activityIndicator
    }()

    // MARK: - Init
    public init(media: MediaDownloadable) {
        self.media = media
        super.init(nibName: nil, bundle: nil)
    }

    required public init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    deinit {
        zoomableImageview.delegate = nil
    }

    //  MARK: - View Controller Life Cycle
    public override func viewDidLoad() {
        super.viewDidLoad()

        zoomableImageview.delegate = self
        zoomableImageview.frame = view.bounds
        zoomableImageview.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        view.addSubview(zoomableImageview)

        view.addSubview(activityIndicator)
        activityIndicator.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
        activityIndicator.autoresizingMask = [.flexibleTopMargin, .flexibleLeftMargin, .flexibleRightMargin, .flexibleBottomMargin]
        activityIndicator.sizeToFit()

        view.addGestureRecognizer(doubleTapGestureRecognizer)

        if let image = media.image {
            zoomableImageview.image = image
            activityIndicator.stopAnimating()
        } else {
            loadmedia()
        }
    }

    public override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        zoomableImageview.frame = view.bounds
    }

    // MARK: - Private
    private func loadmedia() {
        view.bringSubview(toFront: activityIndicator)
        media.loadImageWithCompletionHandler({ [weak self] (image, error) -> () in
            let completeLoading = {
                self?.activityIndicator.stopAnimating()
                self?.zoomableImageview.image = image
            }

            if Thread.isMainThread {
                completeLoading()
            } else {
                DispatchQueue.main.async(execute: { () -> Void in
                    completeLoading()
                })
            }
        })
    }

    @objc private func handleDoubleTapWithGestureRecognizer(_ recognizer: UITapGestureRecognizer) {
        let pointInView = recognizer.location(in: zoomableImageview.imageView)
        var newZoomScale = zoomableImageview.maximumZoomScale

        if zoomableImageview.zoomScale >= zoomableImageview.maximumZoomScale ||
            abs(zoomableImageview.zoomScale - zoomableImageview.maximumZoomScale) <= 0.01 {
            newZoomScale = zoomableImageview.minimumZoomScale
        }

        let scrollViewSize = zoomableImageview.bounds.size
        let width = scrollViewSize.width / newZoomScale
        let height = scrollViewSize.height / newZoomScale
        let originX = pointInView.x - (width / 2.0)
        let originY = pointInView.y - (height / 2.0)

        let rectToZoom = CGRect(x: originX, y: originY, width: width, height: height)
        zoomableImageview.zoom(to: rectToZoom, animated: true)
    }

    // MARK:- UIScrollViewDelegate
    public func viewForZooming(in scrollView: UIScrollView) -> UIView? {
        return zoomableImageview.imageView
    }

    public func scrollViewWillBeginZooming(_ scrollView: UIScrollView, with view: UIView?) {
        scrollView.panGestureRecognizer.isEnabled = true
    }

    public func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
        if (scrollView.zoomScale == scrollView.minimumZoomScale) {
            scrollView.panGestureRecognizer.isEnabled = false
        }
    }
}


================================================
FILE: A_J_Full_Screen_Image_Browser/core/ZoomableImageView.swift
================================================
//
//  ZoomableImageView.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Junliang Jiang on 25/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

final public class ZoomableImageView: UIScrollView {

    // MARK: - Property
    public lazy var imageView: UIImageView = {
        let imageView = UIImageView(frame: bounds)
        addSubview(imageView)
        return imageView
    }()

    public var image: UIImage? {
        didSet {
            updateImage(image)
        }
    }

    override public var frame: CGRect {
        didSet {
            updateZoomScale()
            centerScrollViewContents()
        }
    }

    // MARK: - Init
    override public init(frame: CGRect) {
        super.init(frame: frame)
        setupImageScrollView()
        updateZoomScale()
    }

    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupImageScrollView()
        updateZoomScale()
    }

    private func setupImageScrollView() {
        showsVerticalScrollIndicator = false
        showsHorizontalScrollIndicator = false;
        bouncesZoom = true;
        decelerationRate = UIScrollViewDecelerationRateFast;
    }

    // MARK: - View Life Cycle
    override public func didAddSubview(_ subview: UIView) {
        super.didAddSubview(subview)
        centerScrollViewContents()
    }

    // MARK: - Private
    private func centerScrollViewContents() {
        var horizontalInset: CGFloat = 0
        var verticalInset: CGFloat = 0

        if contentSize.width < bounds.width {
            horizontalInset = (bounds.width - contentSize.width) * 0.5
        }

        if contentSize.height < bounds.height {
            verticalInset = (bounds.height - contentSize.height) * 0.5
        }

        if window?.screen.scale < 2.0 {
            horizontalInset = floor(horizontalInset)
            verticalInset = floor(verticalInset)
        }

        contentInset = UIEdgeInsetsMake(verticalInset, horizontalInset, verticalInset, horizontalInset);
    }

    private func updateImage(_ image: UIImage?) {
        let size = image?.size ?? CGSize.zero

        imageView.transform = CGAffineTransform.identity
        imageView.image = image
        imageView.frame = CGRect(origin: .zero, size: size)
        contentSize = size

        updateZoomScale()
        centerScrollViewContents()
    }

    private func updateZoomScale() {
        guard let image = imageView.image else { return }

        let scrollViewFrame = bounds
        let scaleWidth = scrollViewFrame.size.width / image.size.width
        let scaleHeight = scrollViewFrame.size.height / image.size.height
        let minScale = min(scaleWidth, scaleHeight)

        minimumZoomScale = minScale
        maximumZoomScale = max(minScale, maximumZoomScale)

        if abs(minScale - maximumZoomScale) < 0.01 {
            maximumZoomScale = minScale * 3.0
        }

        zoomScale = minimumZoomScale
        panGestureRecognizer.isEnabled = false
    }
}


/// Make binary `<` operator to accept optional
///
/// - Parameters:
///   - lhs: expression on the left hand side of the `<`
///   - rhs: expression on the right hand side of the `<`
/// - Returns: Boolen value of the comparsion
private func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
    switch (lhs, rhs) {
    case let (l?, r?):
        return l < r
    case (nil, _?):
        return true
    default:
        return false
    }
}


================================================
FILE: A_J_Full_Screen_Image_Browser/helper/SingleMedia.swift
================================================
//
//  SingleMedia.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Alex Jiang on 26/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

/// A concrete media type for supporting both image and video to be downloadable
public final class SingleMedia: MediaDownloadable {

    // MARK: - Properties
    public var image: UIImage?
    public var imageURL: URL?
    public var videoURL: URL?
    public var isVideoThumbnail: Bool

    // MARK: - Init
    public init(imageURL: URL?, isVideoThumbnail: Bool = false, videoURL: URL? = nil) {
        self.imageURL = imageURL
        self.videoURL = videoURL
        self.isVideoThumbnail = isVideoThumbnail
    }

    // MARK: - Downloadable
    public func loadImageWithCompletionHandler(_ completion: @escaping (UIImage?, NSError?) -> ()) {
        if let image = image {
            completion(image, nil)
            return
        }
        loadImageWithURL(imageURL, completion: completion)
    }

    // override this method to use your favourite networking service
    public func loadImageWithURL(_ url: URL?, completion: @escaping (_ image: UIImage?, _ error: NSError?) -> ()) {
        let session = URLSession(configuration: URLSessionConfiguration.default)
        guard let imageURL = url else { completion(nil, NSError(domain: "FullScreenImageBrowserDomain", code: -2, userInfo: [ NSLocalizedDescriptionKey: "Image URL not found."])); return }

        session.dataTask(with: imageURL, completionHandler: {[unowned self] (response, data, error) in
            DispatchQueue.main.async {
                if error != nil {
                    completion(nil, error as NSError?)
                } else if let response = response, let image = UIImage(data: response) {
                    completion(self.isVideoThumbnail ? image.aj_imageWithPlayIcon() : image, nil)
                } else {
                    completion(nil, NSError(domain: "FullScreenImageBrowserDomain", code: -1, userInfo: [ NSLocalizedDescriptionKey: "Couldn't load image"]))
                }
                session.finishTasksAndInvalidate()
            }
        }).resume()
    }
}


================================================
FILE: A_J_Full_Screen_Image_Browser/helper/UIImage+Ex.swift
================================================
//
//  UIImage+Ex.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Alex Jiang on 27/4/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

public extension UIImage {
    public func aj_imageWithPlayIcon() -> UIImage {
        guard let bundlePath = Bundle(for: SingleMedia.self).path(forResource: "FullScreenImageBrowser", ofType: "bundle") else { return self }
        guard let playButtonImage = UIImage(named: "video-play-icon", in: Bundle(path: bundlePath), compatibleWith: nil) else { return self }

        UIGraphicsBeginImageContextWithOptions(size, false, 0.0)
        draw(in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
        let width = min(size.width, size.height) * 0.2
        let x = size.width / 2.0 - width / 2.0
        let y = size.height / 2.0 - width / 2.0
        playButtonImage.draw(in: CGRect(x: x, y: y, width: width, height: width))

        guard let result = UIGraphicsGetImageFromCurrentImageContext() else { return self }
        UIGraphicsEndImageContext()

        return result
    }
}


================================================
FILE: A_J_Full_Screen_Image_Browser/helper/UIView+SnapShot.swift
================================================
//
//  UIView+SnapShot.swift
//  A_J_Full_Screen_Image_Browser
//
//  Created by Junliang Jiang on 25/2/18.
//  Copyright © 2018 Junliang Jiang. All rights reserved.
//

import UIKit

public extension UIView {

    /// Create snapshot view with layer transform information if available
    ///
    /// - Returns: A new view object based on a snapshot of the current view’s rendered contents
    public func aj_snapshotView() -> UIView {
        guard let contents = layer.contents else {
            return snapshotView(afterScreenUpdates: true) ?? UIView()
        }

        var snapshotedView: UIView!

        if let view = self as? UIImageView {
            snapshotedView = type(of: view).init(image: view.image)
            snapshotedView.bounds = view.bounds
        } else {
            snapshotedView = UIView(frame: frame)
            snapshotedView.layer.contents = contents
            snapshotedView.layer.bounds = layer.bounds
        }
        snapshotedView.layer.cornerRadius = layer.cornerRadius
        snapshotedView.layer.masksToBounds = layer.masksToBounds
        snapshotedView.contentMode = contentMode
        snapshotedView.transform = transform

        return snapshotedView
    }

    /// Converts a point from the coordinate space of the current object to the container view coordinate space.
    ///
    /// - Parameter containerView: container view for the point
    /// - Returns: A point specified in the container view coordinate space.
    public func aj_translatedCenterPointToContainerView(_ containerView: UIView) -> CGPoint {
        var centerPoint = center

        if let scrollView = self.superview as? UIScrollView , scrollView.zoomScale != 1.0 {
            centerPoint.x += (scrollView.bounds.width - scrollView.contentSize.width) / 2.0 + scrollView.contentOffset.x
            centerPoint.y += (scrollView.bounds.height - scrollView.contentSize.height) / 2.0 + scrollView.contentOffset.y
        }
        return self.superview?.convert(centerPoint, to: containerView) ?? .zero
    }
}


================================================
FILE: A_J_Full_Screen_Image_Browser.xcodeproj/project.pbxproj
================================================
// !$*UTF8*$!
{
	archiveVersion = 1;
	classes = {
	};
	objectVersion = 48;
	objects = {

/* Begin PBXBuildFile section */
		14DE4D4A20424E77003C7BF4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14DE4D4920424E77003C7BF4 /* AppDelegate.swift */; };
		14DE4D4C20424E77003C7BF4 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14DE4D4B20424E77003C7BF4 /* ViewController.swift */; };
		14DE4D4F20424E77003C7BF4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 14DE4D4D20424E77003C7BF4 /* Main.storyboard */; };
		14DE4D5120424E77003C7BF4 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 14DE4D5020424E77003C7BF4 /* Assets.xcassets */; };
		14DE4D5420424E77003C7BF4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 14DE4D5220424E77003C7BF4 /* LaunchScreen.storyboard */; };
		D6E787282092CEC1007E64C1 /* UIImage+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6E787272092CEC1007E64C1 /* UIImage+Ex.swift */; };
		D6EE23322044E41B00E8C3AF /* SingleMedia.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6EE23302044E41B00E8C3AF /* SingleMedia.swift */; };
		D6EE23332044E41B00E8C3AF /* UIView+SnapShot.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6EE23312044E41B00E8C3AF /* UIView+SnapShot.swift */; };
		D6EE233F2044E45700E8C3AF /* FullScreenImageBrowser.bundle in Resources */ = {isa = PBXBuildFile; fileRef = D6EE23352044E45700E8C3AF /* FullScreenImageBrowser.bundle */; };
		D6EE23402044E45700E8C3AF /* FullScreenImageTransitionAnimator.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6EE23372044E45700E8C3AF /* FullScreenImageTransitionAnimator.swift */; };
		D6EE23412044E45700E8C3AF /* FullScreenImageBrowser.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6EE23392044E45700E8C3AF /* FullScreenImageBrowser.swift */; };
		D6EE23422044E45700E8C3AF /* FullScreenImageBrowserViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6EE233A2044E45700E8C3AF /* FullScreenImageBrowserViewModel.swift */; };
		D6EE23432044E45700E8C3AF /* MediaDownloadable.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6EE233B2044E45700E8C3AF /* MediaDownloadable.swift */; };
		D6EE23442044E45700E8C3AF /* MaskImageViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6EE233C2044E45700E8C3AF /* MaskImageViewer.swift */; };
		D6EE23452044E45700E8C3AF /* SingleImageViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6EE233D2044E45700E8C3AF /* SingleImageViewer.swift */; };
		D6EE23462044E45700E8C3AF /* ZoomableImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D6EE233E2044E45700E8C3AF /* ZoomableImageView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
		14DE4D4620424E77003C7BF4 /* A_J_Full_Screen_Image_Browser.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = A_J_Full_Screen_Image_Browser.app; sourceTree = BUILT_PRODUCTS_DIR; };
		14DE4D4920424E77003C7BF4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
		14DE4D4B20424E77003C7BF4 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
		14DE4D4E20424E77003C7BF4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
		14DE4D5020424E77003C7BF4 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
		14DE4D5320424E77003C7BF4 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
		14DE4D5520424E77003C7BF4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
		D6E787272092CEC1007E64C1 /* UIImage+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Ex.swift"; sourceTree = "<group>"; };
		D6EE23302044E41B00E8C3AF /* SingleMedia.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleMedia.swift; sourceTree = "<group>"; };
		D6EE23312044E41B00E8C3AF /* UIView+SnapShot.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+SnapShot.swift"; sourceTree = "<group>"; };
		D6EE23352044E45700E8C3AF /* FullScreenImageBrowser.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = FullScreenImageBrowser.bundle; sourceTree = "<group>"; };
		D6EE23372044E45700E8C3AF /* FullScreenImageTransitionAnimator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FullScreenImageTransitionAnimator.swift; sourceTree = "<group>"; };
		D6EE23392044E45700E8C3AF /* FullScreenImageBrowser.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FullScreenImageBrowser.swift; sourceTree = "<group>"; };
		D6EE233A2044E45700E8C3AF /* FullScreenImageBrowserViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FullScreenImageBrowserViewModel.swift; sourceTree = "<group>"; };
		D6EE233B2044E45700E8C3AF /* MediaDownloadable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MediaDownloadable.swift; sourceTree = "<group>"; };
		D6EE233C2044E45700E8C3AF /* MaskImageViewer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaskImageViewer.swift; sourceTree = "<group>"; };
		D6EE233D2044E45700E8C3AF /* SingleImageViewer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SingleImageViewer.swift; sourceTree = "<group>"; };
		D6EE233E2044E45700E8C3AF /* ZoomableImageView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ZoomableImageView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
		14DE4D4320424E77003C7BF4 /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
		14DE4D3D20424E77003C7BF4 = {
			isa = PBXGroup;
			children = (
				14DE4D4820424E77003C7BF4 /* A_J_Full_Screen_Image_Browser */,
				14DE4D4720424E77003C7BF4 /* Products */,
			);
			sourceTree = "<group>";
		};
		14DE4D4720424E77003C7BF4 /* Products */ = {
			isa = PBXGroup;
			children = (
				14DE4D4620424E77003C7BF4 /* A_J_Full_Screen_Image_Browser.app */,
			);
			name = Products;
			sourceTree = "<group>";
		};
		14DE4D4820424E77003C7BF4 /* A_J_Full_Screen_Image_Browser */ = {
			isa = PBXGroup;
			children = (
				D6EE23382044E45700E8C3AF /* core */,
				D6EE232F2044E41B00E8C3AF /* helper */,
				D6EE23342044E45700E8C3AF /* asset */,
				D6EE23362044E45700E8C3AF /* animator */,
				14DE4D4920424E77003C7BF4 /* AppDelegate.swift */,
				14DE4D4B20424E77003C7BF4 /* ViewController.swift */,
				14DE4D4D20424E77003C7BF4 /* Main.storyboard */,
				14DE4D5020424E77003C7BF4 /* Assets.xcassets */,
				14DE4D5220424E77003C7BF4 /* LaunchScreen.storyboard */,
				14DE4D5520424E77003C7BF4 /* Info.plist */,
			);
			path = A_J_Full_Screen_Image_Browser;
			sourceTree = "<group>";
		};
		D6EE232F2044E41B00E8C3AF /* helper */ = {
			isa = PBXGroup;
			children = (
				D6EE23302044E41B00E8C3AF /* SingleMedia.swift */,
				D6EE23312044E41B00E8C3AF /* UIView+SnapShot.swift */,
				D6E787272092CEC1007E64C1 /* UIImage+Ex.swift */,
			);
			path = helper;
			sourceTree = "<group>";
		};
		D6EE23342044E45700E8C3AF /* asset */ = {
			isa = PBXGroup;
			children = (
				D6EE23352044E45700E8C3AF /* FullScreenImageBrowser.bundle */,
			);
			path = asset;
			sourceTree = "<group>";
		};
		D6EE23362044E45700E8C3AF /* animator */ = {
			isa = PBXGroup;
			children = (
				D6EE23372044E45700E8C3AF /* FullScreenImageTransitionAnimator.swift */,
			);
			path = animator;
			sourceTree = "<group>";
		};
		D6EE23382044E45700E8C3AF /* core */ = {
			isa = PBXGroup;
			children = (
				D6EE23392044E45700E8C3AF /* FullScreenImageBrowser.swift */,
				D6EE233A2044E45700E8C3AF /* FullScreenImageBrowserViewModel.swift */,
				D6EE233B2044E45700E8C3AF /* MediaDownloadable.swift */,
				D6EE233C2044E45700E8C3AF /* MaskImageViewer.swift */,
				D6EE233D2044E45700E8C3AF /* SingleImageViewer.swift */,
				D6EE233E2044E45700E8C3AF /* ZoomableImageView.swift */,
			);
			path = core;
			sourceTree = "<group>";
		};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
		14DE4D4520424E77003C7BF4 /* A_J_Full_Screen_Image_Browser */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = 14DE4D5820424E77003C7BF4 /* Build configuration list for PBXNativeTarget "A_J_Full_Screen_Image_Browser" */;
			buildPhases = (
				14DE4D4220424E77003C7BF4 /* Sources */,
				14DE4D4320424E77003C7BF4 /* Frameworks */,
				14DE4D4420424E77003C7BF4 /* Resources */,
			);
			buildRules = (
			);
			dependencies = (
			);
			name = A_J_Full_Screen_Image_Browser;
			productName = A_J_Full_Screen_Image_Browser;
			productReference = 14DE4D4620424E77003C7BF4 /* A_J_Full_Screen_Image_Browser.app */;
			productType = "com.apple.product-type.application";
		};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
		14DE4D3E20424E77003C7BF4 /* Project object */ = {
			isa = PBXProject;
			attributes = {
				LastSwiftUpdateCheck = 0920;
				LastUpgradeCheck = 0920;
				ORGANIZATIONNAME = "Junliang Jiang";
				TargetAttributes = {
					14DE4D4520424E77003C7BF4 = {
						CreatedOnToolsVersion = 9.2;
						ProvisioningStyle = Manual;
					};
				};
			};
			buildConfigurationList = 14DE4D4120424E77003C7BF4 /* Build configuration list for PBXProject "A_J_Full_Screen_Image_Browser" */;
			compatibilityVersion = "Xcode 8.0";
			developmentRegion = en;
			hasScannedForEncodings = 0;
			knownRegions = (
				en,
				Base,
			);
			mainGroup = 14DE4D3D20424E77003C7BF4;
			productRefGroup = 14DE4D4720424E77003C7BF4 /* Products */;
			projectDirPath = "";
			projectRoot = "";
			targets = (
				14DE4D4520424E77003C7BF4 /* A_J_Full_Screen_Image_Browser */,
			);
		};
/* End PBXProject section */

/* Begin PBXResourcesBuildPhase section */
		14DE4D4420424E77003C7BF4 /* Resources */ = {
			isa = PBXResourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				14DE4D5420424E77003C7BF4 /* LaunchScreen.storyboard in Resources */,
				14DE4D5120424E77003C7BF4 /* Assets.xcassets in Resources */,
				14DE4D4F20424E77003C7BF4 /* Main.storyboard in Resources */,
				D6EE233F2044E45700E8C3AF /* FullScreenImageBrowser.bundle in Resources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXResourcesBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
		14DE4D4220424E77003C7BF4 /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				D6EE23432044E45700E8C3AF /* MediaDownloadable.swift in Sources */,
				D6EE23452044E45700E8C3AF /* SingleImageViewer.swift in Sources */,
				D6EE23332044E41B00E8C3AF /* UIView+SnapShot.swift in Sources */,
				14DE4D4C20424E77003C7BF4 /* ViewController.swift in Sources */,
				D6E787282092CEC1007E64C1 /* UIImage+Ex.swift in Sources */,
				D6EE23402044E45700E8C3AF /* FullScreenImageTransitionAnimator.swift in Sources */,
				D6EE23322044E41B00E8C3AF /* SingleMedia.swift in Sources */,
				D6EE23422044E45700E8C3AF /* FullScreenImageBrowserViewModel.swift in Sources */,
				D6EE23442044E45700E8C3AF /* MaskImageViewer.swift in Sources */,
				14DE4D4A20424E77003C7BF4 /* AppDelegate.swift in Sources */,
				D6EE23462044E45700E8C3AF /* ZoomableImageView.swift in Sources */,
				D6EE23412044E45700E8C3AF /* FullScreenImageBrowser.swift in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
		14DE4D4D20424E77003C7BF4 /* Main.storyboard */ = {
			isa = PBXVariantGroup;
			children = (
				14DE4D4E20424E77003C7BF4 /* Base */,
			);
			name = Main.storyboard;
			sourceTree = "<group>";
		};
		14DE4D5220424E77003C7BF4 /* LaunchScreen.storyboard */ = {
			isa = PBXVariantGroup;
			children = (
				14DE4D5320424E77003C7BF4 /* Base */,
			);
			name = LaunchScreen.storyboard;
			sourceTree = "<group>";
		};
/* End PBXVariantGroup section */

/* Begin XCBuildConfiguration section */
		14DE4D5620424E77003C7BF4 /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_SEARCH_USER_PATHS = NO;
				CLANG_ANALYZER_NONNULL = YES;
				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_COMMA = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
				CLANG_WARN_STRICT_PROTOTYPES = YES;
				CLANG_WARN_SUSPICIOUS_MOVE = YES;
				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				CODE_SIGN_IDENTITY = "iPhone Developer";
				COPY_PHASE_STRIP = NO;
				DEBUG_INFORMATION_FORMAT = dwarf;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				ENABLE_TESTABILITY = YES;
				GCC_C_LANGUAGE_STANDARD = gnu11;
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_OPTIMIZATION_LEVEL = 0;
				GCC_PREPROCESSOR_DEFINITIONS = (
					"DEBUG=1",
					"$(inherited)",
				);
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				IPHONEOS_DEPLOYMENT_TARGET = 11.2;
				MTL_ENABLE_DEBUG_INFO = YES;
				ONLY_ACTIVE_ARCH = YES;
				SDKROOT = iphoneos;
				SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
				SWIFT_OPTIMIZATION_LEVEL = "-Onone";
			};
			name = Debug;
		};
		14DE4D5720424E77003C7BF4 /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ALWAYS_SEARCH_USER_PATHS = NO;
				CLANG_ANALYZER_NONNULL = YES;
				CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
				CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
				CLANG_CXX_LIBRARY = "libc++";
				CLANG_ENABLE_MODULES = YES;
				CLANG_ENABLE_OBJC_ARC = YES;
				CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
				CLANG_WARN_BOOL_CONVERSION = YES;
				CLANG_WARN_COMMA = YES;
				CLANG_WARN_CONSTANT_CONVERSION = YES;
				CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
				CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
				CLANG_WARN_EMPTY_BODY = YES;
				CLANG_WARN_ENUM_CONVERSION = YES;
				CLANG_WARN_INFINITE_RECURSION = YES;
				CLANG_WARN_INT_CONVERSION = YES;
				CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
				CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
				CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
				CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
				CLANG_WARN_STRICT_PROTOTYPES = YES;
				CLANG_WARN_SUSPICIOUS_MOVE = YES;
				CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
				CLANG_WARN_UNREACHABLE_CODE = YES;
				CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
				CODE_SIGN_IDENTITY = "iPhone Developer";
				COPY_PHASE_STRIP = NO;
				DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
				ENABLE_NS_ASSERTIONS = NO;
				ENABLE_STRICT_OBJC_MSGSEND = YES;
				GCC_C_LANGUAGE_STANDARD = gnu11;
				GCC_NO_COMMON_BLOCKS = YES;
				GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
				GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
				GCC_WARN_UNDECLARED_SELECTOR = YES;
				GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
				GCC_WARN_UNUSED_FUNCTION = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				IPHONEOS_DEPLOYMENT_TARGET = 11.2;
				MTL_ENABLE_DEBUG_INFO = NO;
				SDKROOT = iphoneos;
				SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
				VALIDATE_PRODUCT = YES;
			};
			name = Release;
		};
		14DE4D5920424E77003C7BF4 /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
				CODE_SIGN_STYLE = Manual;
				DEVELOPMENT_TEAM = "";
				INFOPLIST_FILE = A_J_Full_Screen_Image_Browser/Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
				PRODUCT_BUNDLE_IDENTIFIER = "io.pigfly.A-J-Full-Screen-Image-Browser";
				PRODUCT_NAME = "$(TARGET_NAME)";
				PROVISIONING_PROFILE_SPECIFIER = "";
				SWIFT_VERSION = 4.0;
				TARGETED_DEVICE_FAMILY = "1,2";
			};
			name = Debug;
		};
		14DE4D5A20424E77003C7BF4 /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
				CODE_SIGN_STYLE = Manual;
				DEVELOPMENT_TEAM = "";
				INFOPLIST_FILE = A_J_Full_Screen_Image_Browser/Info.plist;
				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
				PRODUCT_BUNDLE_IDENTIFIER = "io.pigfly.A-J-Full-Screen-Image-Browser";
				PRODUCT_NAME = "$(TARGET_NAME)";
				PROVISIONING_PROFILE_SPECIFIER = "";
				SWIFT_VERSION = 4.0;
				TARGETED_DEVICE_FAMILY = "1,2";
			};
			name = Release;
		};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
		14DE4D4120424E77003C7BF4 /* Build configuration list for PBXProject "A_J_Full_Screen_Image_Browser" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				14DE4D5620424E77003C7BF4 /* Debug */,
				14DE4D5720424E77003C7BF4 /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Release;
		};
		14DE4D5820424E77003C7BF4 /* Build configuration list for PBXNativeTarget "A_J_Full_Screen_Image_Browser" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				14DE4D5920424E77003C7BF4 /* Debug */,
				14DE4D5A20424E77003C7BF4 /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Release;
		};
/* End XCConfigurationList section */
	};
	rootObject = 14DE4D3E20424E77003C7BF4 /* Project object */;
}


================================================
FILE: A_J_Full_Screen_Image_Browser.xcodeproj/project.xcworkspace/contents.xcworkspacedata
================================================
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
   version = "1.0">
   <Group
      location = "group:../A_J_Full_Screen_Image_Browser/animator"
      name = "animator">
      <FileRef
         location = "group:FullScreenImageTransitionAnimator.swift">
      </FileRef>
   </Group>
   <Group
      location = "group:../A_J_Full_Screen_Image_Browser/asset"
      name = "asset">
      <FileRef
         location = "group:FullScreenImageBrowser.bundle">
      </FileRef>
   </Group>
   <Group
      location = "group:../A_J_Full_Screen_Image_Browser/core"
      name = "core">
      <FileRef
         location = "group:FullScreenImageBrowser.swift">
      </FileRef>
      <FileRef
         location = "group:FullScreenImageBrowserViewModel.swift">
      </FileRef>
      <FileRef
         location = "group:Image+AsyncDownload.swift">
      </FileRef>
      <FileRef
         location = "group:MaskImageViewer.swift">
      </FileRef>
      <FileRef
         location = "group:SingleImageViewer.swift">
      </FileRef>
      <FileRef
         location = "group:ZoomableImageView.swift">
      </FileRef>
   </Group>
   <Group
      location = "group:../A_J_Full_Screen_Image_Browser/helper"
      name = "helper">
      <FileRef
         location = "group:SingleImage.swift">
      </FileRef>
      <FileRef
         location = "group:UIView+SnapShot.swift">
      </FileRef>
   </Group>
   <FileRef
      location = "self:">
   </FileRef>
</Workspace>


================================================
FILE: A_J_Full_Screen_Image_Browser.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>IDEDidComputeMac32BitWarning</key>
	<true/>
</dict>
</plist>


================================================
FILE: LICENSE
================================================
Copyright (c) 2018 Junliang Jiang Foundation (https://pigfly.github.io)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

================================================
FILE: README.md
================================================
<p align="center">
    <img src="https://github.com/pigfly/A_J_Full_Screen_Image_Browser/blob/master/assets/logo.png?raw=true">
</p>

# A-J-Full-Screen-Image-Browser

![Travis](https://img.shields.io/travis/USER/REPO.svg)
![Code](https://img.shields.io/badge/code-%E2%98%85%E2%98%85%E2%98%85%E2%98%85%E2%98%85-brightgreen.svg)
![Swift](https://img.shields.io/badge/Swift-%3E%3D%203.1-orange.svg)
![npm](https://img.shields.io/npm/l/express.svg)

A-J-Full-Screen-Image-Browser is an drop-in solution for full screen image and video browser

## Features

- [x] No Dependency, 100% iOS Native
- [x] Support both iPad and iPhone family
- [x] Support image resizing on different screen orientation
- [x] Support multiple videos and images
- [x] Image can be panned, zoomed and rotated
- [x] Double tap to zoom all the way in and again to zoom all the way out
- [x] Swipe to dismiss
- [x] High level diagram
- [x] MVVM architecture
- [x] Full documentation
- [x] Easy to customise

## Requirements

- iOS 9.0+ / macOS 10.10+ / tvOS 9.0+ / watchOS 2.0+
- Xcode 9.0+
- Swift 4.0+

## Installation

- drag and drop the entire `A_J_Full_Screen_Image_Browser` into your project

## Full Usage Example

```swift
import UIKit

final class ViewController: UIViewController {

    lazy var testVideo: MediaDownloadable = {
        return SingleMedia(imageURL: URL(string: "https://dummyimage.com/600&text=thumbnail")!,
                    isVideoThumbnail: true,
                    videoURL: URL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!)
    }()

    lazy var media: [MediaDownloadable] = {
        return [testVideo,
                SingleMedia(imageURL: URL(string: "https://dummyimage.com/300")!),
                SingleMedia(imageURL: URL(string: "https://dummyimage.com/600")!),
                testVideo]
    }()

    @IBAction func onButtonTapped(_ sender: UIButton) {
        let vm = FullScreenImageBrowserViewModel(media: media)
        let browser = FullScreenImageBrowser(viewModel: vm)
        present(browser, animated: true, completion: nil)
    }

}
```

## AlamofireImage Support

> By default, `FullScreenImageBrowser` doesn't use any 3rd library, the `SingleImage` uses `URLSession` to fetch image. However it's designed to be compatible with any networking library, one good example is [AlamofireImage](https://github.com/Alamofire/AlamofireImage)

The following code snippet shows an example how to use `AlamofireImage` to seamlessly integrated with `FullScreenImageBrowser`.

```swift
import Foundation
import AlamofireImage

public class FullScreenImage: MediaDownloadable {
    public var image: UIImage?
    public var imageURL: URL?
    public var videoURL: URL?
    public var isVideoThumbnail: Bool

    public init(imageURL: URL?, isVideoThumbnail: Bool = false, videoURL: URL? = nil) {
        self.imageURL = imageURL
        self.videoURL = videoURL
        self.isVideoThumbnail = isVideoThumbnail
    }

    public func loadImageWithCompletionHandler(_ completion: @escaping (UIImage?, NSError?) -> Void) {
        if let image = image {
            completion(image, nil)
            return
        }
        loadImageWithURL(imageURL, completion: completion)
    }

    // use any network calls you like
    public func loadImageWithURL(_ url: URL?, completion: @escaping (_ image: UIImage?, _ error: NSError?) -> Void) {
        guard let _url = url else {
            completion(nil, NSError(domain: "FullScreenImageBrowserDomain",
                                    code: -2,
                                    userInfo: [ NSLocalizedDescriptionKey: "Image URL not found."]))
            return
        }
        let urlRequest = URLRequest(url: _url)

        downloader.download(urlRequest) { [weak self] response in
            debugPrint(response.result)

            if let remoteImage = response.result.value {
                self?.image = remoteImage
                completion(remoteImage, nil)
            } else {
                completion(nil, NSError(domain: "FullScreenImageBrowserDomain",
                                        code: -1,
                                        userInfo: [ NSLocalizedDescriptionKey: "Couldn't load image from remote"]))
            }
        }
    }
}
```

## Folder Structure

```shell
├── animator
│   └── FullScreenImageTransitionAnimator.swift
├── asset
│   └── FullScreenImageBrowser.bundle
│       ├── close.png
│       ├── close@2x.png
│       └── close@3x.png
├── core
│   ├── FullScreenImageBrowser.swift
│   ├── FullScreenImageBrowserViewModel.swift
│   ├── MediaDownloadable.swift
│   ├── MaskImageViewer.swift
│   ├── SingleImageViewer.swift
│   └── ZoomableImageView.swift
└── helper
    ├── SingleImage.swift
    └── UIView+SnapShot.swift
```

| File                                 | Responsiblity                                                                        |
|--------------------------------------|--------------------------------------------------------------------------------------|
| animator                             | customised fade in/fade out animations with damping factors                          |
| asset                                | customised static image asset for the full screen image/video browser navigation bar |
| core/FullScreenImageBrowser          | manager class to be responsible for full screen image/video browser                  |
| core/FullScreenImageBrowserViewModel | datasource and business logic for full screen image/video browser                    |
| core/MediaDownloadable               | protocol to define images to be able to asynchronously download                      |
| core/MaskImageViewer                 | `customised` overlay view for full screen image/video browser                        |
| core/SingleImageViewer               | view controller to be responsible for single image rendering on the full screen      |
| core/ZoomableImageView               | view to add support for image to zoom, pin, rotate, and animation                    |

## Demo

<p align="center">
    <img src="https://github.com/pigfly/A_J_Full_Screen_Image_Browser/blob/master/assets/demo.gif?raw=true">
</p>

<p align="center">
    <img src="https://github.com/pigfly/A_J_Full_Screen_Image_Browser/blob/master/assets/demo2.gif?raw=true">
</p>

<p align="center">
    <img src="https://github.com/pigfly/A_J_Full_Screen_Image_Browser/blob/master/assets/demo3.gif?raw=true">
</p>

<p align="center">
    <img src="https://github.com/pigfly/A_J_Full_Screen_Image_Browser/blob/master/assets/demo4.gif?raw=true">
</p>

<p align="center">
    <img src="https://github.com/pigfly/A_J_Full_Screen_Image_Browser/blob/master/assets/demo5.gif?raw=true">
</p>

<p align="center">
    <img src="https://github.com/pigfly/A_J_Full_Screen_Image_Browser/blob/master/assets/demo6.gif?raw=true">
</p>

## HLD

<p align="center">
    <img src="https://github.com/pigfly/A_J_Full_Screen_Image_Browser/blob/master/assets/hld.png?raw=true">
</p>


## Credits

A-J-Full-Screen-Image-Browser is owned and maintained by the [Alex Jiang](https://pigfly.github.io). Thanks [iTMan.design](https://itman.design) for providing computational resources.

## License

A-J-Full-Screen-Image-Browser is released under the MIT license.
Download .txt
gitextract_g2d1cdig/

├── .gitignore
├── A_J_Full_Screen_Image_Browser/
│   ├── AppDelegate.swift
│   ├── Assets.xcassets/
│   │   └── AppIcon.appiconset/
│   │       └── Contents.json
│   ├── Base.lproj/
│   │   ├── LaunchScreen.storyboard
│   │   └── Main.storyboard
│   ├── Info.plist
│   ├── ViewController.swift
│   ├── animator/
│   │   └── FullScreenImageTransitionAnimator.swift
│   ├── core/
│   │   ├── FullScreenImageBrowser.swift
│   │   ├── FullScreenImageBrowserViewModel.swift
│   │   ├── MaskImageViewer.swift
│   │   ├── MediaDownloadable.swift
│   │   ├── SingleImageViewer.swift
│   │   └── ZoomableImageView.swift
│   └── helper/
│       ├── SingleMedia.swift
│       ├── UIImage+Ex.swift
│       └── UIView+SnapShot.swift
├── A_J_Full_Screen_Image_Browser.xcodeproj/
│   ├── project.pbxproj
│   └── project.xcworkspace/
│       ├── contents.xcworkspacedata
│       └── xcshareddata/
│           └── IDEWorkspaceChecks.plist
├── LICENSE
└── README.md
Condensed preview — 22 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (85K chars).
[
  {
    "path": ".gitignore",
    "chars": 501,
    "preview": "# Xcode\n#\n# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore\n\n"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/AppDelegate.swift",
    "chars": 2198,
    "preview": "//\n//  AppDelegate.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Junliang Jiang on 25/2/18.\n//  Copyright © "
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/Assets.xcassets/AppIcon.appiconset/Contents.json",
    "chars": 1495,
    "preview": "{\n  \"images\" : [\n    {\n      \"idiom\" : \"iphone\",\n      \"size\" : \"20x20\",\n      \"scale\" : \"2x\"\n    },\n    {\n      \"idiom\""
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/Base.lproj/LaunchScreen.storyboard",
    "chars": 1681,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<document type=\"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/Base.lproj/Main.storyboard",
    "chars": 2933,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<document type=\"com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB\" version=\"3"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/Info.plist",
    "chars": 1561,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/ViewController.swift",
    "chars": 1037,
    "preview": "//\n//  ViewController.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Junliang Jiang on 25/2/18.\n//  Copyright"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/animator/FullScreenImageTransitionAnimator.swift",
    "chars": 7550,
    "preview": "//\n//  TransitionAnimator.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Junliang Jiang on 25/2/18.\n//  Copyr"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/core/FullScreenImageBrowser.swift",
    "chars": 10544,
    "preview": "//\n//  FullScreenImageBrowser.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Junliang Jiang on 25/2/18.\n//  C"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/core/FullScreenImageBrowserViewModel.swift",
    "chars": 1377,
    "preview": "//\n//  FullScreenImageBrowserViewModel.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Alex Jiang on 26/2/18.\n"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/core/MaskImageViewer.swift",
    "chars": 4989,
    "preview": "//\n//  MaskImageViewer.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Junliang Jiang on 25/2/18.\n//  Copyrigh"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/core/MediaDownloadable.swift",
    "chars": 555,
    "preview": "//\n//  MediaDownloadable.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Junliang Jiang on 25/2/18.\n//  Copyri"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/core/SingleImageViewer.swift",
    "chars": 4438,
    "preview": "//\n//  SingleMediaViewer.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Junliang Jiang on 25/2/18.\n//  Copyri"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/core/ZoomableImageView.swift",
    "chars": 3467,
    "preview": "//\n//  ZoomableImageView.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Junliang Jiang on 25/2/18.\n//  Copyri"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/helper/SingleMedia.swift",
    "chars": 2154,
    "preview": "//\n//  SingleMedia.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Alex Jiang on 26/2/18.\n//  Copyright © 2018"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/helper/UIImage+Ex.swift",
    "chars": 1075,
    "preview": "//\n//  UIImage+Ex.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Alex Jiang on 27/4/18.\n//  Copyright © 2018 "
  },
  {
    "path": "A_J_Full_Screen_Image_Browser/helper/UIView+SnapShot.swift",
    "chars": 2036,
    "preview": "//\n//  UIView+SnapShot.swift\n//  A_J_Full_Screen_Image_Browser\n//\n//  Created by Junliang Jiang on 25/2/18.\n//  Copyrigh"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser.xcodeproj/project.pbxproj",
    "chars": 18822,
    "preview": "// !$*UTF8*$!\n{\n\tarchiveVersion = 1;\n\tclasses = {\n\t};\n\tobjectVersion = 48;\n\tobjects = {\n\n/* Begin PBXBuildFile section *"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser.xcodeproj/project.xcworkspace/contents.xcworkspacedata",
    "chars": 1456,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Workspace\n   version = \"1.0\">\n   <Group\n      location = \"group:../A_J_Full_Scre"
  },
  {
    "path": "A_J_Full_Screen_Image_Browser.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist",
    "chars": 238,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/P"
  },
  {
    "path": "LICENSE",
    "chars": 1095,
    "preview": "Copyright (c) 2018 Junliang Jiang Foundation (https://pigfly.github.io)\n\nPermission is hereby granted, free of charge, t"
  },
  {
    "path": "README.md",
    "chars": 7278,
    "preview": "<p align=\"center\">\n    <img src=\"https://github.com/pigfly/A_J_Full_Screen_Image_Browser/blob/master/assets/logo.png?raw"
  }
]

About this extraction

This page contains the full source code of the pigfly/A_J_Full_Screen_Image_Browser GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 22 files (76.6 KB), approximately 20.8k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!