• Stars
    star
    247
  • Rank 164,117 (Top 4 %)
  • Language
    Swift
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

More Repositories

1

NKJPagerViewController

NKJPagerViewController is like a PagerTabStrip, which is in Android. It contains an endlessly scrollable UIScrollView.
Objective-C
117
star
2

Shari

Shari is the alternative to the library of UIPickerView(drum roll) in Swift. You can select a item using UITableView.
Swift
114
star
3

NKJMovieComposer

NKJMovieComposer is very simple movie composer for iOS.
Swift
40
star
4

Ubaguruma

Ubaguruma is a photo select picker like LINE.
Swift
37
star
5

Sengiri

Sengiri is the screen recording utility. It can easily create GIF movie.
Swift
22
star
6

Ajimi

Ajimi means tasting. In Japanese, 味見. Ajimi is the feedback tool, which anyone can easily feedback to project team any time.
Swift
18
star
7

NKJMultiMovieCaptureView

CaptureSessionView to save videos while touching the screen
Swift
14
star
8

VersionUpdater

Notify users when a new version of your app is available and force them to upgrade the application of the version.
Swift
10
star
9

teiten

Teiten is an app that fixed-point observation a lot earnestly yourself by using a PC camera. 定点観測アプリ
Swift
10
star
10

ColorHex

Initializes the UIColor using hexadecimal.
Swift
9
star
11

SwiftSampleApp

Simple Application For Swift
Swift
8
star
12

frustrationme_app

Web Service - Social Wish Management
Ruby
5
star
13

dotfiles

console setting info
Emacs Lisp
4
star
14

jquery-cool-grid

calclate item's height and show items
CoffeeScript
4
star
15

nakajichan

say
Ruby
3
star
16

NKJPhotoSliderController

PhotoSlider can a simple photo slider and delete slider with swiping.
Objective-C
3
star
17

unkore_iphone

iPhone Game - Bureau of Nakajima Cleansing
Objective-C
3
star
18

podspec_bump

A command line tools to bump podspec version for CocoaPods.
Ruby
3
star
19

NoticeGitHubIssue

Ruby
2
star
20

post-feeds-in-irc

Post feeds in IRC
Ruby
2
star
21

SwiftSampleAppForCollectionView

Try to create a simple application using CollectionView (Normal Version and RxSwift Version)
Swift
2
star
22

frustrationme_chrome_extension

Chrome Extension for http://www.frustration.me
JavaScript
1
star
23

frustrationme_chrome_app

Chrome App for http://www.frustration.me
1
star
24

Zend_Framework_Db_Adapter_Pdo

Zend Framework側でSQLログを吐かせる方法
PHP
1
star
25

Zend_Framework_View_Smarty

Zend FrameworkでSmartyを利用する
PHP
1
star