测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最后发布 | 2017年10月 |
SwiftSwift 版本 | 4.0 |
SPM支持 SPM | ✗ |
由 Tangent 维护。
一个具有操作表风格的图片选择控件。支持 iCloud。
照片按创建顺序显示。
当你在 iCloud 中选择一张照片时,PhotosSheet
将自动从远程下载。
photo library usage privacy
添加到项目的 Info.plist
中。在 $ cd Sample/
和 $ pod install
后,启动 Xcode 中的 Sample
项目以查看 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
支持多种媒体选项
您可以使用 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
可以显示发送原始文件的按钮
只需将 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)