PhotoSlider, PhotoSlider是一个简单的照片滑块,可以通过滑动来删除滑块

分享于 

7分钟阅读

GitHub

  繁體 雙語
PhotoSlider can a simple photo slider and delete slider with swiping.
  • 源代码名称:PhotoSlider
  • 源代码网址:http://www.github.com/nakajijapan/PhotoSlider
  • PhotoSlider源代码文档
  • PhotoSlider源代码下载
  • Git URL:
    git://www.github.com/nakajijapan/PhotoSlider.git
    Git Clone代码到本地:
    git clone http://www.github.com/nakajijapan/PhotoSlider
    Subversion代码到本地:
    $ svn co --depth empty http://www.github.com/nakajijapan/PhotoSlider
    Checked out revision 1.
    $ cd repo
    $ svn up trunk
    
    用于Swift的 PhotoSlider

    CarthageVersionLicensePlatformLanguage

    PhotoSlider是一个简单的照片 slider,可以通过滑动来删除 slider。

    要求

    • Xcode 9 +
    • 快速 4.0 +
    • iOS 10 +

    安装

    CocoaPods

    PhotoSlider可以通过 CocoaPods 获得。 要安装它,只需在你的Podfile中添加以下行:

    pod "PhotoSlider"

    Carthage

    Carthage 是 Cocoa 应用程序的分散依赖管理器。

    $ brew update
    $ brew install carthage

    要使用Carthage将PhotoSlider集成到你的Xcode项目中,请在你的Cartfile 中指定它:

    
    github"nakajijapan/PhotoSlider"
    
    
    
    

    然后,运行下面的命令来构建PhotoSlider框架:

    $ carthage update

    用法

    使用 ZoomingAnimationControllerTransitioning

    funccollectionView(collectionView: UICollectionView, didSelectItemAtIndexPathindexPath: NSIndexPath) {
     var slider = PhotoSlider.ViewController(imageURLs: self.images)
     slider.currentPage= indexPath.row photoSlider.transitioningDelegate=selfpresent(photoSlider, animated: true, completion: nil)
    }
    ZoomingAnimationControllerTransitioning

    返回起始位置的imageView

    // MARK: ZoomingAnimationControllerTransitioningfunctransitionSourceImageView() -> UIImageView {
     let indexPath = collectionView.indexPathsForSelectedItems?.firstlet 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=. scaleAspectFillreturn imageView
    }

    返回完成位置的sourceImageView

    functransitionDestinationImageView(sourceImageView: UIImageView) {
     guardlet image = sourceImageView.imageelse {
     return }
     let indexPath = collectionView.indexPathsForSelectedItems?.firstlet cell = collectionView.cellForItem(at: indexPath!) as! ImageCollectionViewCell
     let statusBarHeight = UIApplication.shared.statusBarFrame.height// snip.. sourceImageView.frame= frame
    }
    UIViewControllerTransitioningDelegate
    // MARK: UIViewControllerTransitioningDelegatefuncanimationController(forDismisseddismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
     let animationController = PhotoSlider.ZoomingAnimationController(present: false)
     animationController.sourceTransition= dismissed as? ZoomingAnimationControllerTransitioning
     animationController.destinationTransition=selfreturn animationController
    }funcanimationController(forPresentedpresented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
     let animationController = PhotoSlider.ZoomingAnimationController(present: true)
     animationController.sourceTransition= source as? ZoomingAnimationControllerTransitioning
     animationController.destinationTransition= presented as? ZoomingAnimationControllerTransitioning
     return animationController
    }

    使用 UIModalTransitionStyle

    选择 ZoomingAnimationController

    funccollectionView(collectionView: UICollectionView, didSelectItemAtIndexPathindexPath: NSIndexPath) {
     var slider = PhotoSlider.ViewController(imageURLs: self.images)
     slider.modalPresentationStyle=. OverCurrentContext slider.modalTransitionStyle= UIModalTransitionStyle.CrossDissolve slider.index= indexPath.rowself.presentViewController(slider, animated: true, completion: nil)
    }

    委托

    你可以处理以下事件:

    • 可选的函数 photoSliderControllerWillDismiss ( viewController: PhotoSlider.ViewController )
    • 可选的函数 photoSliderControllerDidDismiss ( viewController: PhotoSlider.ViewController )

    多映像加载程序

    PhotoSlider使用Kingfisher进行远程图像处理。 如果在项目中使用 SDWebImage,则在Kingfisher和SDWebImage之间不共享图像缓存。 在这种情况下,你可以制作自定义 ImageLoader。 默认ImageLoader为 Kingfisher。

    下面是更改SDWebImage的方法。

    首先,创建定制 ImageLoader。

    importPhotoSliderclassPhotoSliderSDImageLoader: PhotoSlider.ImageLoader {
     publicfuncload(
     imageView: UIImageView?,
     fromURLurl: URL?,
     progress: @escaping PhotoSlider.ImageLoader.ProgressBlock,
     completion: @escaping PhotoSlider.ImageLoader.CompletionBlock)
     {
     imageView?.sd_setImage(
     withURL: url,
     placeholderImage: nil,
     options: SDWebImageOptions.retryFailed,
     progress: { (receivedSize, totalSize) inprogress(receivedSize, totalSize)
     },
     completed: { (image, _, _, _) incompletion(image)
     }
     )
     }
    }

    并设置 ImageLoader。

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

    作者

    nakajijapan

    特别感谢

    • hikarock
    • yhkaplan
    • seapy
    • antrix1989

    许可证

    PhotoSlider在MIT许可证下可用。 有关详细信息,请参阅许可证文件。


    sli  DEL  Slide  Slider  
    相关文章