Git Product home page Git Product logo

photoslider's Introduction

PhotoSlider for Swift

Carthage Version License Platform

PhotoSlider can a simple photo slider and delete slider with swiping.

Requirements

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

Installation

CocoaPods

PhotoSlider is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "PhotoSlider"

Carthage

Carthage is a decentralized dependency manager for Cocoa application.

$ brew update
$ brew install carthage

To integrate Kingfisher into your Xcode project using Carthage, specify it in your Cartfile:

github "nakajijapan/PhotoSlider"

Then, run the following command to build the Kingfisher framework:

$ carthage update

Usage

Using ZoomingAnimationControllerTransitioning

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    var slider = PhotoSlider.ViewController(imageURLs: self.images)
    slider.currentPage = indexPath.row
    photoSlider.transitioningDelegate = self
    self.presentViewController(slider, animated: true, completion: nil)

}

ZoomingAnimationControllerTransitioning

return imageView for starting position

// MARK: ZoomingAnimationControllerTransitioning

func transitionSourceImageView() -> UIImageView {

let indexPath = self.collectionView.indexPathsForSelectedItems()?.first

    let cell = self.collectionView.cellForItemAtIndexPath(indexPath!) as! ImageCollectionViewCell
    let imageView = UIImageView(image: cell.imageView.image)

    var frame = cell.imageView.frame
    frame.origin.y += UIApplication.sharedApplication().statusBarFrame.height

    imageView.frame = frame
    imageView.clipsToBounds = true
    imageView.contentMode = UIViewContentMode.ScaleAspectFill

    return imageView

}

return sourceImageView for finished position

func transitionDestinationImageView(sourceImageView: UIImageView) {
    
    guard let image = sourceImageView.image else {
        return
    }
    
    let indexPath = self.collectionView.indexPathsForSelectedItems()?.first
    let cell = self.collectionView.cellForItemAtIndexPath(indexPath!) as! ImageCollectionViewCell
    let statusBarHeight = UIApplication.sharedApplication().statusBarFrame.height

    // snip..

    sourceImageView.frame = frame
    
}

UIViewControllerTransitioningDelegate

// MARK: UIViewControllerTransitioningDelegate

func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    let animationController = PhotoSlider.ZoomingAnimationController(present: false)
    animationController.sourceTransition = dismissed as? ZoomingAnimationControllerTransitioning
    animationController.destinationTransition = self
    return animationController
}

func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    let animationController = PhotoSlider.ZoomingAnimationController(present: true)
    animationController.sourceTransition = source as? ZoomingAnimationControllerTransitioning
    animationController.destinationTransition = presented as? ZoomingAnimationControllerTransitioning
    return animationController
}

Using UIModalTransitionStyle

select ZoomingAnimationController

func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {

    var slider = PhotoSlider.ViewController(imageURLs: self.images)
    slider.modalPresentationStyle = .OverCurrentContext
    slider.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
    slider.index = indexPath.row
    self.presentViewController(slider, animated: true, completion: nil)

}

Delegation

You can handle the following event:

  • optional func photoSliderControllerWillDismiss(viewController: PhotoSlider.ViewController)
  • optional func photoSliderControllerDidDismiss(viewController: PhotoSlider.ViewController)

Author

nakajijapan, [email protected]

License

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

photoslider's People

Contributors

antrix1989 avatar bati668 avatar elkraneo avatar nakajijapan avatar zubko avatar

Watchers

 avatar  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.