SYGalleryPicker 1.2.3

SYGalleryPicker 1.2.3

jj2564 维护。




SYGalleryPicker

一个照片选择库。

新闻

  • 现在支持 iOS14 权限。

要求

iOS 10

安装

SYGalleryPicker 通过 CocoaPods 提供。将以下行添加到您的 Podfile 中

pod "SYGalleryPicker"

在终端中输入

$ pod install --repo-update

演示

使用方法

let vc = SYGalleryPickerViewController()
vc.modalPresentationStyle = .fullScreen
vc.syPresentGalleryPickerController(self, animated: true,
select: { asset in
    print(asset.description)
}, deselect: { asset in
    print(asset.description)
}, cancel: { assets in
    print("Cancel")
}, finish: { assets in
    print("Confirm")
}, photoSelectLimitReached: { count in
    print("Limit reach")
}, authorizedDenied: nil, authorizedLimited: {
        print("is now limited")
}, completion: nil )

使用闭包而不是代理,如果不需要则可以设置为 nil

整个函数看起来像这样

func syPresentGalleryPickerController
(_ viewController: UIViewController, style: SelectStyle = .basic, customSetting:SYGalleryPickerSettings? = nil , requestOptions: PHImageRequestOptions? = nil, animated: Bool,
select: ((_ asset: PHAsset) -> Void)?,
deselect: ((_ asset: PHAsset) -> Void)?,
cancel: (([PHAsset]) -> Void)?,
finish: (([PHAsset]) -> Void)?,
photoSelectLimitReached: ((Int) -> Void)?,
authorizedDenied:(() -> Void)?,
authorizedLimited:(() -> Void)? = nil,
completion: (() -> Void)? ) {}

如果你使用 customSetting 参数,则 style 将不进行设置。所有设置都将遵循自定义设置。

当调用 syPresentGalleryPickerController 时,你也可以将 PHImageRequestOptions 设置为 requestOptions。如果不设置,将会这样

imageRequestOptions = PHImageRequestOptions()
imageRequestOptions?.deliveryMode = .highQualityFormat
imageRequestOptions?.resizeMode = .exact
imageRequestOptions?.isNetworkAccessAllowed = false

设置

设置必须遵循 SYGalleryPickerSettings 协议。

public protocol SYGalleryPickerSettings {

    // MARK: Enviorment
    /// status bar style
    var statusBarStyle: UIStatusBarStyle { get }
    /// select limit count in picker
    var pickLimitCount: Int { get }
    /// count per row in picker
    var countInRow: (_ verticalSize: UIUserInterfaceSizeClass, _ horizontalSize: UIUserInterfaceSizeClass) -> Int { get }
    /// use a title text instead of album select
    var titleText: Bool { get }
    /// text with confirm button
    var confirmButtonText: String { get }
    
    // MARK: Picker Style
    /// color of navigation bar
    var tintColor: UIColor? { get }
    /// color of navigation title
    var tintTextColor: UIColor? { get }
    /// background color of picker
    var backgroundColor: UIColor { get }
    
    // MARK: Selected style
    /// select mark and select border color
    var pickedColor: UIColor { get }
    /// select mark location of the cell
    var pickedMarkLocation: selectLocation { get }
    /// use count on select view
    var isPickedWithCount: Bool { get }
    /// show select border ot not
    var isPickWithBorder: Bool { get }

}

如果您想自定义样式,请创建一个新的类并继承 SYGalleryPickerSettings。您可以这样设置值

final class IMSetting: SYGalleryPickerSettings {

    var pickLimitCount: Int = 10
    var cancelButtonText: String = "取消"
    var confirmButtonText: String = "確認"
    var pickedColor: UIColor = .green_008800
    var isPickedWithCount: Bool = false
    var isPickWithBorder: Bool = false
}

您不需要安装所有设置。

默认选择

PHAsset 设置为 Array 并将其设置为 defaultSelections

let default_selection:[PHAsset] = [...]
let vc = SYGalleryPickerViewController()
vc.defaultSelections = default_selection

请注意,如果 defaultSelections 的数量超过限制,它仍将选中。

待办事项

  • 清除因最新要求而产生的废弃代码
  • 解决奇怪问题
  • 将数据源与单元格分开
  • 用户删除照片后刷新
  • icloud图片测试
  • 单元测试

参考

BSImagePicker
这个库很强大,但我的要求很特殊。

作者

jj2564, [email protected]

许可证

SYGalleryPicker遵循MIT许可证。有关更多信息,请参阅LICENSE文件。