Coder Social home page Coder Social logo

nakajijapan / photoslider Goto Github PK

View Code? Open in Web Editor NEW
248.0 11.0 60.0 45.97 MB

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

License: MIT License

Swift 95.82% Ruby 2.90% C 0.46% Objective-C 0.81%
swift kingfisher carthage viewcontroller photo-slider sdwebimage xcode

photoslider's Introduction

PhotoSlider for Swift

Carthage Version License Platform Language Backers on Open Collective Sponsors on Open Collective

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

Requirements

  • Xcode 9+
  • Swift 4.0+
  • iOS 10+

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 PhotoSlider into your Xcode project using Carthage, specify it in your Cartfile:

github "nakajijapan/PhotoSlider"

Then, run the following command to build the PhotoSlider 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
    present(photoSlider, animated: true, completion: nil)

}

ZoomingAnimationControllerTransitioning

return imageView for starting position

// MARK: ZoomingAnimationControllerTransitioning

func transitionSourceImageView() -> UIImageView {

    let indexPath = collectionView.indexPathsForSelectedItems?.first
    let cell = collectionView.cellForItem(at: indexPath!) as! ImageCollectionViewCell
    let imageView = UIImageView(image: cell.imageView.image)

    var frame = cell.imageView.frame
    frame.origin.y += UIApplication.shared.statusBarFrame.height

    imageView.frame = frame
    imageView.clipsToBounds = true
    imageView.contentMode = .scaleAspectFill

    return imageView

}

return sourceImageView for finished position

func transitionDestinationImageView(sourceImageView: UIImageView) {

    guard let image = sourceImageView.image else {
        return
    }

    let indexPath = collectionView.indexPathsForSelectedItems?.first
    let cell = collectionView.cellForItem(at: indexPath!) as! ImageCollectionViewCell
    let statusBarHeight = UIApplication.shared.statusBarFrame.height

    // snip..

    sourceImageView.frame = frame

}

UIViewControllerTransitioningDelegate

// MARK: UIViewControllerTransitioningDelegate

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

func animationController(forPresented presented: UIViewController, presenting: UIViewController, 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)

Multiple Image Loader

PhotoSlider use Kingfisher for remote image. If use SDWebImage in your project, image cache is not shared between Kingfisher and SDWebImage. In this case you can make custom ImageLoader. default ImageLoader is Kingfisher.

Here is how to change SDWebImage.

First, create custom ImageLoader.

import PhotoSlider

class PhotoSliderSDImageLoader: PhotoSlider.ImageLoader {
    public func load(
        imageView: UIImageView?,
        fromURL url: URL?,
        progress: @escaping PhotoSlider.ImageLoader.ProgressBlock,
        completion: @escaping PhotoSlider.ImageLoader.CompletionBlock)
    {
        // Webp compatibility (optional)
        let WebPCoder = SDImageWebPCoder.shared
        SDImageCodersManager.shared.addCoder(WebPCoder)
        
        imageView?.sd_setImage(
            withURL: url,
            placeholderImage: nil,
            options: SDWebImageOptions.retryFailed,
            progress: { (receivedSize, totalSize) in
                progress(receivedSize, totalSize)
            },
            completed: { (image, _, _, _) in
                completion(image)
            }
        )
    }
}

and set ImageLoader.

let slider = PhotoSlider.ViewController(imageURLs: images)
slider.modalPresentationStyle = .OverCurrentContext
slider.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
slider.index = indexPath.row
slider.imageLoader = PhotoSliderSDImageLoader()
present(slider, animated: true, completion: nil)

Author

nakajijapan

Special Thanks

  • hikarock
  • yhkaplan
  • seapy
  • antrix1989

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers! πŸ™ [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

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

photoslider's People

Contributors

antrix1989 avatar elkraneo avatar hikarock avatar monkeywithacupcake avatar nakajijapan avatar noppefoxwolf avatar omarjalil avatar seapy avatar yhkaplan avatar zubko 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  avatar

photoslider's Issues

slider.index = indexPath.row error after pod update

Hi,
as I wrote in the title, after upgrading from version 0.4.0 to 0.6.0, the line "slider.index = indexPath.row" gives me an error but deleting it my app seams to work correctly.
I just wanted to report for let the instructions up to date.

PS: any plan to fix the rotation behavior on iPad?
Many thanks

Zoom problem

In previous versions of PhotoSlider was possible zooming images once open. With 0.14.1 is not possible anymore.

The init code

var photos: [PhotoSlider.Photo] = []
for image in images {
photos += [PhotoSlider.Photo(imageURL:image, caption: "")]
}
let slider = PhotoSlider.ViewController(photos: photos )
slider.currentPage = index
slider.visiblePageControl = false
viewController.present(slider, animated: true, completion: nil)

crash in iOs 11

In iOs 11 PhotoSlider crach on "effectView.addSubview(backgroundView)" in ViewController.swift. Works with "effectView.contentView.addSubview(backgroundView)"

Autorotation problem

Hi, I'm implementing your work into my project (thank you for sharing) and it seams I was able to do it correctly.

Unfortunately I've got problems during rotation while I'm inside the PhotoSlider.ViewController: moving the orientation from there produces a weird disposition of the view. It seams like it misses the new framework size.
Because I'm a beginner I wasn't able to solve it alone. Could you give an hint about it?
Thank you
Alessandro

Compile error in swift 3 and Xcode 8.2

Some compile error when i use PhotoSlider

???/PhotoSlider/Sources/Classes/ImageView.swift:127:21: Heterogenous collection literal could only be inferred to '[String : Any]'; add explicit type annotation if this is intentional

i use swift 3 and Xcode 8.2

Version for swift 3

When running on xcode 8 it shows a lot of error, when it will be unstable to swift 3

Image load from exist object

Reuse image not remote url when application already has a image object.

like this

var myImage = UIImage(named: 'wow')
var slider = PhotoSlider.ViewController(images: [myImage])

change background color

Hello,
I am trying to change the background color of the PhotoSlider view controller.
So far the PhotoSliderViewcontroller itself changes fine, but the transition doesn't look really nice now, since the origin and destination viewcontroller have white background and the transition has a black background color.
Is there a way to make this change smoother?

StatusBar shown only device

Statusbar is hidden with simulator, but statusbar is shown with device.

And in 4 inch(ex iPhone 5) device, close button not touched well(this issue also with device, not simulator)

Swift Package Fail

Xcode 11
"PhotoSlider >=0.14.2 contains incompatible tools version and root depends on PhotoSlider 1.0.0, version solving failed."

Thanks for your help ;-)

Pod issue

Pod doesn't grab the latest version.

The status bar is not hidden

I noticed that the status bar is not hidden β€”it's just black.

This can be a problem in two cases:

  1. When the iPhone is charging (the battery shows up as green)
  2. When the status bar is set to white in the app it's used in

I'll make a PR when I have time in the next week or two πŸ˜‰

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.