CocoaPods trunk is moving to be read-only. Read more on the blog, there are 17 months to go.

CPImageViewer 4.0.0

CPImageViewer 4.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Oct 2016
SPMSupports SPM

Maintained by Wei Zhao.



  • By
  • Wei Zhao

CPImageViewer

Viewing a single image using transition animation. Supporting presentation and push & pop.

Screenshot

Present & Dismiss

Push & Pop

Installation

Manually

The simplest way to install this library is to copy Classes/*.swift to your project.

Properties

These properties is global and applied to the whole project.

/// The viewer style. Defaults to Presentation
public var viewerStyle = CPImageViewerStyle.presentation

/// The image of animation image view
public var image: UIImage?

/// The title of *navigationItem.rightBarButtonItem* when viewerStyle is Push
public var rightBarItemTitle: String?

/// The image of *navigationItem.rightBarButtonItem* when viewerStyle is Push
public var rightBarItemImage: UIImage?

/// The action of *navigationItem.rightBarButtonItem* when viewerStyle is Push
public var rightAction: ((Void) -> (Void))?

Usage

It’s very easy to use CPImageViewer.

Firstly, conforming to CPImageControllerProtocol protocol and initializing the animationImageView or assigning it an image view.

class ViewController: UIViewController, ImageControllerProtocol {
  var animationImageView: UIImageView!
}

override func viewDidLoad() {
    animationImageView = UIImageView()
    animationImageView.frame = <#frame#>
    animationImageView.image = <#image#>
    self.view.addSubview(animationImageView)
}

Then, presenting the CPImageViewerViewController

let controller = CPImageViewerViewController()
controller.transitioningDelegate = CPImageViewerAnimator()
controller.image = animationImageView.image 
self.presentViewController(controller, animated: true, completion: nil)

or pushing the CPImageViewerViewController

override func viewDidLoad() {
    self.navigationController?.delegate = CPImageViewerAnimator()
}

let controller = CPImageViewerViewController()
controller.viewerStyle = .push
controller.image = animationImageView.image 
controller.title = "CPImageViewer"
self.navigationController?.pushViewController(controller, animated: true)

Requirements

  • Swift 3.0+
  • Xcode 8.0+
  • iOS 8+

License

Released under the MIT license. See LICENSE for details.