PhotosSheet 2.2.1

PhotosSheet 2.2.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布最后发布2017年10月
SwiftSwift 版本4.0
SPM支持 SPM

Tangent 维护。



  • Tangent



介绍

一个具有操作表风格的图片选择控件。支持 iCloud。

照片按创建顺序显示。

当你在 iCloud 中选择一张照片时,PhotosSheet 将自动从远程下载。

PhotosSheet

PhotosSheet
PhotosSheet

要求

  • iOS 9.0 或更高版本。
  • Swift 4.0。
  • 请确保将 photo library usage privacy 添加到项目的 Info.plist 中。

演示

$ cd Sample/$ pod install 后,启动 Xcode 中的 Sample 项目以查看 PhotosSheet 的实际效果。

安装

手动

  1. 下载源代码。
  2. 将文件夹 PhotosSheet 拖放到你的项目中。

使用方法

基本使用

let openCamera = PhotosSheet.Action(title: "Open Camera", tintColor: .green) {
    print("Open Camera")
}
let openAlbum = PhotosSheet.Action(title: "Open Album", tintColor: .green) {
    print("Open Album")
}
let cancel = PhotosSheet.Action(style: .cancel, title: "Cancel", tintColor: .red) {
    print("Cancel")
}

let photosSheet = PhotosSheet(actions: [openCamera, openAlbum, cancel],
                              mediaOption: .photo,
                              displayedPhotosLimit: 50,
                              selectedPhotosLimit: 4) { [weak self] assets in
                                self?._sendAssets(assets)
}
present(photosSheet, animated: true, completion: nil)

PhotosSheet 支持多种媒体选项

  • all
  • photo
  • video

自定义

您可以使用 UIOption 来自定义 PhotosSheet 的 UI。

var options: Set<PhotosSheet.UIOption> {
    return [
        .photoItemCheckboxRightMargin(5),
        .actionSheetItemHeight(57),
        .actionSheetCorners(12),
        .actionSheetFont(.systemFont(ofSize: 20))
    ]
}
let photosSheet = PhotosSheet(actions: [openCamera, openAlbum, cancel],
                              mediaOption: .photo,
                              displayedPhotosLimit: 50,
                              selectedPhotosLimit: 4,
                              options: options) { [weak self] assets in
                                self?._sendAssets(assets)
}

所有属性

photoItemCheckboxRightMargin(CGFloat)
photoItemCheckboxBottomMargin(CGFloat)
photoItemVideoMarkerViewLeftMargin(CGFloat)
photoItemVideoMarkerViewBottomMargin(CGFloat)
photoItemHeight(CGFloat)
actionSheetFont(UIFont)
actionSheetCorners(CGFloat)
actionSheetHorizontalMargin(CGFloat)
actionSheetVerticalMargin(CGFloat)
actionSheetItemHeight(CGFloat)

发送原始文件

PhotosSheet 可以显示发送原始文件的按钮

PhotosSheet

只需将 isShowSendOriginalsButton 设置为 true

photosSheet.isShowSendOriginalsButton = true

如果用户按下“发送原始文件”按钮,PhotosSheet 将回调给我们

let photosSheet = PhotosSheet(actions: [openCamera, openAlbum, cancel],
                              mediaOption: .photo,
                              displayedPhotosLimit: 50,
                              selectedPhotosLimit: 4) { assets, isOriginl in
                                if isOriginl {
                                  // TODO...
                                } else {
                                  // TODO...
                                }
}

过滤器

用户按下发送按钮后,您可以过滤 PhotosSheet 的发送操作:

/// Filter before you have selected the photos.
///
///    let filter: SendingActionFilter = { assets, isOriginals, send in
///        assets.calcSize { size in
///            // Less than 10 MB
///            let canSend = size < 10 * 1024 * 1024
///            send()
///        }
///    }
///
public var sendingActionFilter: SendingActionFilter?

例如

lazy var filter: PhotosSheet.SendingActionFilter = { [weak self] assets, isOriginal, send in
     assets.calcSize { [weak self] size in
         let canSend = size < 10 * 1024 * 1024
         if canSend {
             send()
         } else {
             let alertController = UIAlertController(title: "Warning", message: "Photos size is too large, still want to send?", preferredStyle: .alert)
             let confirmAction = UIAlertAction(title: "Yes", style: .default) { _ in
                 send()
             }
             let cancelAction = UIAlertAction(title: "No", style: .cancel)
             alertController.addAction(confirmAction)
             alertController.addAction(cancelAction)
             self?.present(alertController, animated: true, completion: nil)
         }
     }
 }

photosSheet.sendingActionFilter = filter

界面

/// All actions in action sheet.
public let actions: [PhotosSheet.Action]

/// PhotosSheet is show send originals button.
public var isShowSendOriginalsButton: Bool = false {
    didSet {
        _contentController.isShowSendOriginalsButton = isShowSendOriginalsButton
    }
}

/// Filter before you have selected the photos.
///
///    let filter: SendingActionFilter = { assets, isOriginals, send in
///        assets.calcSize { size in
///            // Less than 10 MB
///            let canSend = size < 10 * 1024 * 1024
///            send()
///        }
///    }
///
public var sendingActionFilter: SendingActionFilter? = nil {
    didSet {
        _contentController.sendingActionFilter = sendingActionFilter
    }
}

/// Init an action sheet with photos on it.
///
/// - Parameters:
///   - actions: Actions in action sheet.
///   - mediaOption: The media option of the asset you want to select.
///   - displayedPhotosLimit: The max count of photos displayed, default is `0`, means unlimited.
///   - selectedPhotosLimit: The max count of photos that can be selected, default is `9`.
///   - options: UI options. See `UIOption`
///   - didSelectedAssets: Called after you have selected the photos. |Assets, Is send originals|
public init(actions: [PhotosSheet.Action],
       mediaOption: MediaOption = .all,
       displayedPhotosLimit: Int = 0,
       selectedPhotosLimit: Int = 9,
       options: Set<UIOption>? = nil,
       didSelectedAssets: @escaping ([PHAsset], Bool) -> ())

待办事项

  • 支持 Live Photo
  • 优化性能

许可证

MIT 许可证 (MIT)