Giter Site home page Giter Site logo

lvnkmn / zoomy Goto Github PK

View Code? Open in Web Editor NEW
206.0 10.0 24.0 94.45 MB

Adds seamless scrollView and instagram like zooming to UIImageViews in any view hierarchy.

License: MIT License

Ruby 0.09% Swift 99.86% C 0.05%
swift uiscrollview zooming cocoapods uiimageview swift4 zoomy hierarchy zoom image

zoomy's Introduction

Zoomy allows you to add seamless scrollView and instagram like zooming to UIImageViews in any view hierarchy.

Example

Example project can be found in the Example folder

Setup

Just add

import Zoomy

to the files that of the code that needs zoombehavior.

Usage

All of the folowing snippets are expected to be called from within to your viewcontroller.

Somewhere after viewDidLoad should work just fine.

Scrollable zooming

addZoombehavior(for: imageView)

Insta zooming

addZoombehavior(for: imageView, settings: .instaZoomSettings)

Zooming above navigationbar/tabbar

guard let parentView = parent?.view else { return }
addZoombehavior(for: imageView, in:parentView)

Zooming below UI element

addZoombehavior(for: imageView, below: dismissButton)

Zooming with some custom gesture actions

let settings = Settings.defaultSettings
    .with(actionOnTapOverlay: Action.dismissOverlay)
    .with(actionOnDoubleTapImageView: Action.zoomIn)
        
addZoombehavior(for: imageView, settings: settings)

There's a lot more triggers and actions to choose from.

Zooming a collectionviewcell

public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    
    //After your regular dequeue and configuration:
    addZoombehavior(for: cell.imageView)
        
    return cell
}

Other examples

A note about zooming images that live inside scrollviews

Zooming inside any viewhierarchy will work perfectly fine using Zoomy, however sometimes you want to disable existing behaviors while zooming. A good example of this is when zooming images that are subviews of a scrollview.

For best performance just implement these Zoomy.Delegate methods:

extension YourViewController: Zoomy.Delegate {
    
    func didBeginPresentingOverlay(for imageView: Zoomable) {
        scrollView.isScrollEnabled = false
    }
    
    func didEndPresentingOverlay(for imageView: Zoomable) {
        scrollView.isScrollEnabled = true
    }
}

No need to set the viewController as a delegate to anyting. This is infered using conditional conformance. In case you're interested in seeing how this is done, see this and this.

Texture

All the code examples provided above work with texture's ImageNode as well. All that is needed for this is adding extension ASImageNode: Zoomable {} anywhere in your targets sources. See the example projects for basic and more advanced usage of texture.

There's more to come

See the roadmap for upcoming features.

Missing anyting or something is not working as desired? Create an issue and it will likely be picked up.

Support

There may not always be time for personal support on how to implement Zoomy in different scenario's. Hopefully the code is clear enough to get done what's needed ๐Ÿ’ช. In case you've implemented a scenario thats not described in this readme or the examples, feel free to create a pull request, that would be pretty cool actually.

Installation

Zoomy is available through Swift Package Manager. To install it, simply add it to your project using this repository's URL as explained here.

Credits & Acknowledgements

Cover photo by Leonardo Yip, all other images that have been used can be found on Unsplash.

License

Zoomy is available under the MIT license. See the LICENSE file for more info.

zoomy's People

Contributors

brendalaupg avatar fulcommit avatar lvnkmn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zoomy's Issues

Simplify API for viewControllers

Remove the need for managing storage of ImageZoomControllers

ViewControllers should have the following API:

func addZoomFunctionality(for imageView: UIImageView, in view: UIView = view, delegate: ImageZoomControllerDelegate? = nil, settings: ImageZoomcontrollerSettings = .defaultSettings)

func removeZoomFunctionality(for imageView: UIImageView)

Retain Cycle

In one of the ImageZoomController states reference to owner should be weak

Improved logging

  • Logging should be possible up to line level
  • Loggers should not be injectable anymore
    • Instead add setting shouldLogWarningsAndErrors

Improved backgroundColor naming

backgroundColorWhenContentIsSmallerThanViewItsDisplayedIn should be: primaryBackgroundColor

backgroundWhenContentFillsViewItsDisplayedIn should be: secundaryBackgroundColor

Assignable actions per interaction

Actions should only be assignable on the interactions that support them. For instance assignment of dismissOverlay should not be possible on assigned to beginPinchOnOriginalImage

Add stackView support

Currently doesn't work in stack view because the original imageView's isVisible is set to false while zooming, this changes the stackView layout.

Scrollview's contentSize and subview frames are sometimes unreliable

In some cases, the scrollView's content size will have really high unexpected values. When this happens, this always seems to be in scrollViewWillBeginDragging.

issue

From this moment on, the absolute frames of the UIScrollView cannot be trusted.

When this happens, the zoomed image will be visible in the wrong size (way too big). This currently only seems to happen when performing a bounce dismiss.

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.