项目作者: shima11

项目描述 :
Image zoomable like Instagram.
高级语言: Swift
项目地址: git://github.com/shima11/InteractiveZoomDriver.git
创建时间: 2018-04-16T05:56:52Z
项目社区:https://github.com/shima11/InteractiveZoomDriver

开源协议:MIT License

下载


InteractiveZoomDriver

This repo is view to zoomable by pinch gesture.

Overview

Installation

Swift Package Manager

For installing with SPM, add it to your Package.swift.

  1. dependencies: [
  2. .package(url: "https://github.com/shima11/InteractiveZoomDriver.git", from: "1.2.5"))
  3. ]

Carthage

For installing with Carthage, add it to your Cartfile.

  1. github "shima11/InteractiveZoomDriver"

CocoaPods

For installing with CocoaPods, add it to your Podfile.

  1. pod 'InteractiveZoomDriver'

Usage

  1. import InteractiveZoomDriver
  2. let zoomView = UIImageView() // UIView or SubClass of UIView
  3. zoomView.isUserInteractionEnabled = true

Case1: driver

Add zoom function to target UIView.

gestureTargetView: added tap and pan gesture.
sourceView: source view.
targetViewFactory: Transformed View during zooming.
shouldZoomTransform: Delegate to the outside whether zooming is possible.

  1. let driver = InteractiveZoomDriver(
  2. gestureTargetView: imageView2,
  3. sourceView: imageView2,
  4. targetViewFactory: { (fromImageView: UIImageView) -> UIView in
  5. let view = UIImageView()
  6. view.image = fromImageView.image
  7. view.clipsToBounds = fromImageView.clipsToBounds
  8. view.contentMode = fromImageView.contentMode
  9. return view
  10. },
  11. shouldZoomTransform: {(sourceView: UIImageView) -> Bool in
  12. if sourceView.image == nil {
  13. return false
  14. }
  15. return true
  16. }
  17. )

This is also no problem.
InteractiveZoomView.clone and InteractiveZoomView.shouldZoomTransform is default implementation of protocol extension.
InteractiveZoomView corresponds to UIImageView only.
To support other than UIImageView, add an implementation in extension.

  1. let driver = InteractiveZoomDriver(
  2. gestureTargetView: zoomView,
  3. sourceView: zoomView,
  4. targetViewFactory: InteractiveZoomView.clone,
  5. shouldZoomTransform: InteractiveZoomView.shouldZoomTransform
  6. )

Case2: overlay view

InteractiveZoomView is able to only UIImageView now.
If you want to use custom UIView, you need to create extension of InteractiveZoomView with reference to InteractiveZoomView.

  1. let overlayZoomView = InteractiveZoomView(
  2. sourceView: zoomView
  3. )
  4. view.addSubView(overlayZoomView)