GithubHelp home page GithubHelp logo

redfin / insphotogallery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tim-woo/insphotogallery

0.0 5.0 1.0 1.94 MB

INSPhotoGallery is a modern looking photo gallery written in Swift for iOS.

Home Page: https://medium.com/inspace-labs-blog/insphotogallery-modern-looking-photo-gallery-written-in-swift-for-ios-7c6b3fdf54da

License: Apache License 2.0

Swift 98.27% Objective-C 0.75% Ruby 0.98%

insphotogallery's Introduction

Introduction

INSPhotoGallery was written by Michał Zaborowski for inspace.io

INSPhotoGallery

INSPhotoGallery is a modern looking photo gallery written in Swift for iOS. INSPhotoGallery can handle downloading of photos but in addition to that it allows you to make custom logic for downloading images, also it allows you to make custom overlay if you won't like current design. In addition it support interactive flick to dismiss, animated zooming presentation and many more. It was inspired by NYTPhotoViewer.

Simple Usage

lazy var photos: [INSPhotoViewable] = {
    return [
        INSPhoto(imageURL: NSURL(string: "http://inspace.io/assets/portfolio/thumb/13-3f15416ddd11d38619289335fafd498d.jpg"), thumbnailImage: UIImage(named: "thumbnailImage")!),
        INSPhoto(imageURL: NSURL(string: "http://inspace.io/assets/portfolio/thumb/13-3f15416ddd11d38619289335fafd498d.jpg"), thumbnailImage: UIImage(named: "thumbnailImage")!),
        INSPhoto(image: UIImage(named: "fullSizeImage")!, thumbnailImage: UIImage(named: "thumbnailImage")!),
    ]
}()
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    let cell = collectionView.cellForItemAtIndexPath(indexPath) as! ExampleCollectionViewCell
    let currentPhoto = photos[indexPath.row]
    let galleryPreview = INSPhotosViewController<INSPhoto>(photos: photos, initialPhoto: currentPhoto, referenceView: cell)

    galleryPreview.referenceViewForPhotoWhenDismissingHandler = { [weak self] photo in
        if let index = self?.photos.indexOf({$0 === photo}) {
            let indexPath = NSIndexPath(forItem: index, inSection: 0)
            return collectionView.cellForItemAtIndexPath(indexPath) as? ExampleCollectionViewCell
        }
        return nil
    }
    presentViewController(galleryPreview, animated: true, completion: nil)
}

Custom Photo Model

You are able to create your custom photo model which can be use instead default INSPhoto. Default implementation don't cache images. If you would like to use some caching mechanism or use some library for downloading images for example HanekeSwift use must implement INSPhotoViewable protocol.

@objc public protocol INSPhotoViewable: class {
    var image: UIImage? { get }
    var thumbnailImage: UIImage? { get }

    func loadImageWithCompletionHandler(completion: (image: UIImage?, error: NSError?) -> ())
    func loadThumbnailImageWithCompletionHandler(completion: (image: UIImage?, error: NSError?) -> ())

    var attributedTitle: NSAttributedString? { get }
}
class CustomPhotoModel: NSObject, INSPhotoViewable {
  var image: UIImage?
  var thumbnailImage: UIImage?

  var imageURL: NSURL?
  var thumbnailImageURL: NSURL?

  func loadImageWithCompletionHandler(completion: (image: UIImage?, error: NSError?) -> ()) {
        if let url = imageURL {
            Shared.imageCache.fetch(URL: url).onSuccess({ image in
                completion(image: image, error: nil)
            }).onFailure({ error in
                completion(image: nil, error: error)
            })
        } else {
            completion(image: nil, error: NSError(domain: "PhotoDomain", code: -1, userInfo: [ NSLocalizedDescriptionKey: "Couldn't load image"]))
        }
    }
}

CocoaPods

Add the following to your Podfile and run $ pod install.

pod 'INSPhotoGallery'

If you don't have CocoaPods installed, you can learn how to do so here.

SPM

For this forked repo, add a new package dependency using:

https://github.com/redfin/INSPhotoGallery.git

And target a commit hash if a release version has not been published yet.

Contact

inspace.io

Twitter

License

Copyright © 2016 Inspace Labs Sp z o. o. Spółka Komandytowa. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this library except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.```

insphotogallery's People

Contributors

amitpdev avatar andreaantonioni avatar annewe avatar dimidrol86 avatar hani-ibrahim avatar jbiscarri avatar m1entus avatar redfinwyland avatar spencerwhyte avatar wallacesky avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

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.