Giter Club home page Giter Club logo

imagescrollview-master's Introduction

ImageScrollView

This is a control that will help you to display an image, with zoomable and scrollable features easily.

About

When you make an application, which has a photo viewer feature, the photo viewer usually needs to have zoomable and scrollable features, that allows your user viewing photo more details. This control will help you to display images, with zoomable and scrollable features easily.

Demo

Compatible

  • iOS 9 and later.
  • Swift 5.0 and later (for earlier Swift version, please use earlier ImageScrollView version).

Usage

Cocoapod

Add below line to your Podfile:

pod 'ImageScrollView'

then run below command in Terminal to install:

pod install

Note: If the above pod doesn't work, try using below pod definition in Podfile:

pod 'ImageScrollView', :git => 'https://github.com/huynguyencong/ImageScrollView.git'

Swift Package Manager

In Xcode, select menu File -> Swift Packages -> Add Package Dependency. Select a target, then add this link to the input field: https://github.com/huynguyencong/ImageScrollView.git

Manual

Sometimes just want to install manually, just simply add the file ImageSrollView.swift in the folder Sources to your project.

Simple to use

Drag an UIScrollView to your storyboard, change Class and Module in Identity Inspector to ImageScrollView. Also, create an IBOutlet in your source file.

How to config ImageScrollView in storyboard

import ImageScrollView
@IBOutlet weak var imageScrollView: ImageScrollView!
// Important: This setup method should be called once, usually in your viewDidLoad() method
imageScrollView.setup()

let myImage = UIImage(named: "my_image_name")
imageScrollView.display(image: myImage)

That's all. Now try zooming and scrolling to see the result.

You can set delegate to catch event. This delegate is inheritted from UIScrollViewDelegate.

imageScrollView.imageScrollViewDelegate = self
extension ViewController: ImageScrollViewDelegate {
    func imageScrollViewDidChangeOrientation(imageScrollView: ImageScrollView) {
        print("Did change orientation")
    }
    
    func scrollViewDidEndZooming(_ scrollView: UIScrollView, with view: UIView?, atScale scale: CGFloat) {
        print("scrollViewDidEndZooming at scale \(scale)")
    }
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        print("scrollViewDidScroll at offset \(scrollView.contentOffset)")
    }
}

Note:

  • If you have any problem about layout, image position, make sure you have called the setup() method of the ImageScrollView. Or you can try calling the method layoutIfNeeded() of the view controller's view:
view.layoutIfNeeded()

About this source

This open source is based on PhotoScroller demo avaiable on Apple's site. The original source was written in Objective C. This open source rewrote it by using Swift, and added some new features:

  • Double tap to zoom.
  • Smoother. Fixed bug when zooming out, the control auto zooms from center, and not from the corner.

License

ImageScrollView is released under the MIT license. See LICENSE for details. Copyright © Nguyen Cong Huy

imagescrollview-master's People

Contributors

kushal334 avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.