Coder Social home page Coder Social logo

pgimagepicker's Introduction

PGImagePicker

PGImagePicker

1、使用UICollectionView进行复用
2、内置了3种样式,有微博和微信的样式
3、双击放大/还原,单击返回,双指粘合缩放,长按保存图片到相册
4、可以自定义相薄

长按保存到相册需要在info.plist中加入以下隐私权限

<key>NSPhotoLibraryAddUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>

如果相册权限被用户拒绝了,PGImagePicker已经设置好了引导用户去APP设置页面开启权限

CocoaPods安装

pod 'PGImagePicker'

使用

let imagePicker = PGImagePicker(currentImageView: tapView, imageViews: imageViews)
present(imagePicker, animated: false, completion: nil)

总共需要传入两个参数。第一个currentImageView当前的UIImageView,第二个参数imageViews需要浏览的所有图片的UIImageView ,如果只需要浏览一张图,则参数imageViews可以省略

单张图片预览

例如点击头像预览

let imagePicker = PGImagePicker(currentImageView: tapView)
present(imagePicker, animated: false, completion: nil)

设置相薄

长按保存到相册,可以自定义相薄,将图片保存到自己定义的相薄里面

imagePicker.albumName = "PGImagePicker"  

设置样式

pageControlType共有3种样式 样式1是当前微信的样式,样式3是当前微博的样式

let imagePicker = PGImagePicker(currentImageView: tapView, pageControlType: .type1, imageViews: imageViews)
present(imagePicker, animated: false, completion: nil)

设置代理

得到当前正在预览的图片

imagePicker.delegate = self
func imagePicker(imagePicker: PGImagePicker, didSelectImageView imageView: UIImageView, didSelectImageViewAt index: Int) {
    print("index = ", index)
}

加载网络图片

加载网络图片使用的是Kingfisher框架

引入pod

pod 'PGImagePickerKingfisher'

使用

let imagePicker = PGImagePickerKingfisher(currentImageView: tapView, imageViews: imageViews)
imagePicker.imageUrls = self.imageUrls
imagePicker.indicatorType = .activity
imagePicker.placeholder = UIImage(named: "projectlist_06")
present(imagePicker, animated: false, completion: nil)

imageUrls是图片需要加载的url地址 indicatorTypeplaceholder跟当前要预览的图片一致,没有可以不用设置

许可证

PGImagePicker 使用 MIT 许可证,详情见 LICENSE 文件。

pgimagepicker's People

Contributors

xiaozhuxiong121 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

Watchers

 avatar  avatar

pgimagepicker's Issues

发现一个bug

如果有一个很长的tableView/collectionView,每个cell/item里有一张图片.
这种情况下是获取不了未展示的图片的frame的.

会导致一个崩溃:

▿ 21 elements
  - 0 : "0   ???                                 0x0000000123b6aba7 0x0 + 4894141351"
  - 1 : "1   ???                                 0x0000000123b6ac95 0x0 + 4894141589"
  - 2 : "2   Coll                                0x000000010a7ac7c0 main + 0"
  - 3 : "3   PGImagePicker                       0x000000010ac36300 _T013PGImagePicker12PGScrollViewC11convertRect33_47910DC33138F0D90388FDFB1D47CA6DLLSQySC6CGRectVGSo6UIViewC3for_tF + 1040"
  - 4 : "4   PGImagePicker                       0x000000010ac389f8 _T013PGImagePicker12PGScrollViewC10tapHandler33_47910DC33138F0D90388FDFB1D47CA6DLLySo7UITouchCFyycfU_ + 312"
  - 5 : "5   PGImagePicker                       0x000000010ac39ae2 _T013PGImagePicker12PGScrollViewC10tapHandler33_47910DC33138F0D90388FDFB1D47CA6DLLySo7UITouchCFyycfU_TA + 50"
  - 6 : "6   PGImagePicker                       0x000000010ac27ca9 _T0Ix_IyB_TR + 41"
  - 7 : "7   UIKit                               0x000000010b9209ec +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] + 560"
  - 8 : "8   UIKit                               0x000000010b920f38 +[UIView(UIViewAnimationWithBlocks) animateWithDuration:animations:completion:] + 86"
  - 9 : "9   PGImagePicker                       0x000000010ac38884 _T013PGImagePicker12PGScrollViewC10tapHandler33_47910DC33138F0D90388FDFB1D47CA6DLLySo7UITouchCF + 1028"
  - 10 : "10  PGImagePicker                       0x000000010ac38e3c _T013PGImagePicker12PGScrollViewC10tapHandler33_47910DC33138F0D90388FDFB1D47CA6DLLySo7UITouchCFTo + 60"
  - 11 : "11  Foundation                          0x000000010ace6609 __NSFireDelayedPerform + 409"
  - 12 : "12  CoreFoundation                      0x000000010ec07374 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20"
  - 13 : "13  CoreFoundation                      0x000000010ec07032 __CFRunLoopDoTimer + 1026"
  - 14 : "14  CoreFoundation                      0x000000010ec06bea __CFRunLoopDoTimers + 266"
  - 15 : "15  CoreFoundation                      0x000000010ebfe604 __CFRunLoopRun + 2308"
  - 16 : "16  CoreFoundation                      0x000000010ebfda89 CFRunLoopRunSpecific + 409"
  - 17 : "17  GraphicsServices                    0x0000000113c679c6 GSEventRunModal + 62"
  - 18 : "18  UIKit                               0x000000010b85ed30 UIApplicationMain + 159"
  - 19 : "19  Coll                                0x000000010a7ac7f7 main + 55"
  - 20 : "20  libdyld.dylib                       0x00000001113ebd81 start + 1"

崩溃原因:
因为没有设置frame, rect为nil, 强制解包失败!

fileprivate func convertRect(for view: UIView) -> CGRect! {
        let rootView = UIApplication.shared.keyWindow?.rootViewController?.view
        let rect = view.superview?.convert(view.frame, to: rootView)
        return rect!
    }

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.