-
Notifications
You must be signed in to change notification settings - Fork 982
How to use (Swift)
long edited this page Oct 26, 2020
·
28 revisions
This class is a configuration class for framework, you can configure each parameter according to your needs.
// example
ZLPhotoConfiguration.default().allowSelectVideo = false
This class is a color configuration class for framework, you can configure each parameter according to your needs.
// example
ZLPhotoConfiguration.default().themeColorDeploy.thumbnailBgColor = .black
let ps = ZLPhotoPreviewSheet()
ps.selectImageBlock = { [weak self] (images, assets, isOriginal) in
// your code
}
ps.showPreview(animate: true, sender: self)
let ps = ZLPhotoPreviewSheet()
ps.selectImageBlock = { [weak self] (images, assets, isOriginal) in
// your code
}
ps.showPhotoLibrary(sender: self)
let camera = ZLCustomCamera()
camera.takeDoneBlock = { [weak self] (image, videoUrl) in
// your code
}
self.showDetailViewController(camera, sender: nil)
// config edit tools
ZLPhotoConfiguration.default().editImageTools = [.draw, .clip, .mosaic]
// config crop ratios
ZLPhotoConfiguration.default().editImageClipRatios = [.custom, .wh1x1, .wh3x4, .wh16x9, ZLImageClipRatio(title: "1 : 2", whRatio: 1 / 2)]
let editVC = ZLEditImageViewController(image: image)
editVC.editFinishBlock = { [weak self] (image) in
// your code
}
editVC.modalPresentationStyle = .fullScreen
self.showDetailViewController(editVC, sender: nil)
class CustomFilter {
class func filterMethod(image: UIImage) -> UIImage {
// 1. create filter.
// 2. process the image.
// 3. return the processed picture.
}
}
ZLPhotoConfiguration.default().filters = [ZLFilter(name: "custom", applier: CustomFilter.filterMethod)]
// edit local file.
let fileUrl = URL(fileURLWithPath: "filePath")
let avAsset = AVAsset(url: fileUrl)
let editVC = ZLEditVideoViewController(avAsset: avAsset, animateDismiss: true)
editVC.editFinishBlock = { (url) in
// your code
}
editVC.modalPresentationStyle = .fullScreen
self.showDetailViewController(editVC, sender: nil)
// Need to be consistent with the framework image name.
ZLPhotoConfiguration.default().customImageNames = ["zl_btn_selected"]
ZLPhotoConfiguration.default().customLanguageKeyValue = [.previewCamera: "Camera"]
if #available(iOS 13.0, *) {
ZLPhotoConfiguration.default().themeColorDeploy.thumbnailBgColor = UIColor.init(dynamicProvider: { (trait) -> UIColor in
if trait.userInterfaceStyle == .dark {
return .black
} else {
return .white
}
})
}
// Must be one of PHAsset, UIImage and URL, framework will filter ohers.
let datas: [Any] = [...]
let videoSuffixs = ["mp4", "mov", "avi", "rmvb", "rm", "flv", "3gp", "wmv", "vob", "dat", "m4v", "f4v", "mkv"] // and more suffixs
let vc = ZLImagePreviewController(datas: datas, index: 0, showSelectBtn: true) { (url) -> ZLURLType in
if let sf = url.absoluteString.split(separator: ".").last, videoSuffixs.contains(String(sf)) {
return .video
} else {
return .image
}
} urlImageLoader: { (url, imageView, progress, loadFinish) in
// Demo used Kingfisher.
imageView.kf.setImage(with: url) { (receivedSize, totalSize) in
let percentage = (CGFloat(receivedSize) / CGFloat(totalSize))
debugPrint("\(percentage)")
progress(percentage)
} completionHandler: { (_) in
loadFinish()
}
}
vc.doneBlock = { (datas) in
// your code
}
vc.modalPresentationStyle = .fullScreen
self.showDetailViewController(vc, sender: nil)