Skip to content

Commit

Permalink
release 4.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
longitachi committed Oct 29, 2020
1 parent c6baed5 commit ee4b05d
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 75 deletions.
20 changes: 19 additions & 1 deletion Example/Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ class ViewController: UIViewController {
}

@objc func previewSelectPhoto() {
// ZLPhotoConfiguration.default().editImageClipRatios = [.custom, .wh1x1, .wh3x4, .wh16x9, ZLImageClipRatio(title: "2 : 1", whRatio: 2 / 1)]
let ac = ZLPhotoPreviewSheet(selectedAssets: self.takeSelectedAssetsSwitch.isOn ? self.selectedAssets : [])
ac.selectImageBlock = { [weak self] (images, assets, isOriginal) in
self?.selectedImages = images
Expand All @@ -131,19 +130,37 @@ class ViewController: UIViewController {
self?.collectionView.reloadData()
debugPrint("\(images) \(assets) \(isOriginal)")
}
ac.cancelBlock = {
debugPrint("cancel select")
}
ac.selectImageRequestErrorBlock = { (errorAssets, errorIndexs) in
debugPrint("fetch error assets: \(errorAssets), error indexs: \(errorIndexs)")
}
ac.showPreview(animate: true, sender: self)
}

@objc func librarySelectPhoto() {
// ZLPhotoConfiguration.default().editImageClipRatios = [.custom, .wh1x1, .wh3x4, .wh16x9, ZLImageClipRatio(title: "2 : 1", whRatio: 2 / 1)]
// ZLPhotoConfiguration.default().filters = [.normal, .process, ZLFilter(name: "custom", applier: ZLCustomFilter.hazeRemovalFilter)]

// You can first determine whether the asset is allowed to be selected.
ZLPhotoConfiguration.default().canSelectAsset = { (asset) -> Bool in
return true
}

let ac = ZLPhotoPreviewSheet(selectedAssets: self.takeSelectedAssetsSwitch.isOn ? self.selectedAssets : [])
ac.selectImageBlock = { [weak self] (images, assets, isOriginal) in
self?.selectedImages = images
self?.selectedAssets = assets
self?.collectionView.reloadData()
debugPrint("\(images) \(assets) \(isOriginal)")
}
ac.cancelBlock = {
debugPrint("cancel select")
}
ac.selectImageRequestErrorBlock = { (errorAssets, errorIndexs) in
debugPrint("fetch error assets: \(errorAssets), error indexs: \(errorIndexs)")
}
ac.showPhotoLibrary(sender: self)
}

Expand Down Expand Up @@ -171,6 +188,7 @@ class ViewController: UIViewController {

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
// Just for demo.
if url.absoluteString == netVideoUrlString {
return .video
}
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ Detailed usage of `Swift` and `OC`, please refer to [Wiki](https://github.com/lo
### <a id="UpdateLog"></a>Update Log
> [More logs](https://github.com/longitachi/ZLPhotoBrowser/blob/master/UPDATELOG.md)
```
● 4.0.8: Add filter to image editor;
● 4.0.7: Image editor support crop ratios; Custom camera supports switching camera during recording; bug fixed;
● 4.0.5: Support iOS14 limited authority; Optimize picture preview display;
● 4.0.9:
Support languages of more countries (French, German, Russian, Vietnamese, Korean, Malay, Italian).
Support iOS14 limited authority.
Provides the ability to preview PHAsset, local images and videos, network images and videos together.
Optimize some UI effects.
● 4.0.8:
Add filter to image editor.
● 4.0.7:
Image editor support crop ratios.
Custom camera supports switching camera during recording.
bug fixed.
...
```

Expand Down
5 changes: 1 addition & 4 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,10 @@
### <a id="更新日志"></a>更新日志
> [更多更新日志](https://github.com/longitachi/ZLPhotoBrowser/blob/master/UPDATELOG.md)
```
● 4.0.9: 支持更多国家的语言; 完善iOS14 limited authority 权限的适配; 提供可以同时预览PHAsset、本地图片/视频及网络图片/视频的功能; 优化部分UI效果;
● 4.0.8: 编辑图片添加滤镜功能;
● 4.0.7: 支持设置图片裁剪比例; 自定义相机支持录制时切换摄像头; 新增已选照片边框功能; 新增是否允许预览大图功能;其他细节优化及已知bug修复;
● 4.0.5: 适配iOS14 limited权限; 优化图片预览显示; 优化大长/宽图编辑;
● 4.0.4: 优化图片编辑体验,记录之前编辑状态; 添加是否允许拍照参数; 优化降序照片获取顺序; fix #510, fix #513; 修复其他已知bug;
● 4.0.2: 新增框架样式设置(新增一种仿微信的样式); 编辑图片添加马赛克功能; 添加下拉返回动画; 自定义相机支持最短录制时间设置; 优化gif照片的回调;
● 4.0.1: 优化视频编辑功能; 增加自定义列数功能; 修复一些bug;
● 4.0.0: 框架升级为纯`Swift`编写,最低支持右`iOS8`升级到`iOS10`;
...
```

Expand Down
59 changes: 36 additions & 23 deletions Sources/General/ZLEmbedAlbumListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// THE SOFTWARE.

import UIKit
import Photos

class ZLEmbedAlbumListView: UIView {

Expand Down Expand Up @@ -105,13 +106,14 @@ class ZLEmbedAlbumListView: UIView {
self.addGestureRecognizer(tap)
}

func loadAlbumList() {
func loadAlbumList(completion: ( () -> Void )? = nil) {
DispatchQueue.global().async {
ZLPhotoManager.getPhotoAlbumList(ascending: ZLPhotoConfiguration.default().sortAscending, allowSelectImage: ZLPhotoConfiguration.default().allowSelectImage, allowSelectVideo: ZLPhotoConfiguration.default().allowSelectVideo) { [weak self] (albumList) in
self?.arrDataSource.removeAll()
self?.arrDataSource.append(contentsOf: albumList)

DispatchQueue.main.async {
completion?()
self?.tableView.reloadData()
}
}
Expand All @@ -133,30 +135,41 @@ class ZLEmbedAlbumListView: UIView {

/// 这里不采用监听相册发生变化的方式,是因为每次变化,系统都会回调多次,造成重复获取相册列表
func show(reloadAlbumList: Bool) {
if reloadAlbumList {
self.loadAlbumList()
}

let toFrame = self.calculateBgViewBounds()

self.isHidden = false
self.alpha = 0
var newFrame = toFrame
newFrame.origin.y -= newFrame.height

if newFrame != self.tableBgView.frame {
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: newFrame.width, height: newFrame.height), byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 8, height: 8))
self.tableBgView.layer.mask = nil
let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
self.tableBgView.layer.mask = maskLayer
func animateShow() {
let toFrame = self.calculateBgViewBounds()

self.isHidden = false
self.alpha = 0
var newFrame = toFrame
newFrame.origin.y -= newFrame.height

if newFrame != self.tableBgView.frame {
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: newFrame.width, height: newFrame.height), byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 8, height: 8))
self.tableBgView.layer.mask = nil
let maskLayer = CAShapeLayer()
maskLayer.path = path.cgPath
self.tableBgView.layer.mask = maskLayer
}

self.tableBgView.frame = newFrame
self.tableView.frame = self.tableBgView.bounds
UIView.animate(withDuration: 0.25) {
self.alpha = 1
self.tableBgView.frame = toFrame
}
}

self.tableBgView.frame = newFrame
self.tableView.frame = self.tableBgView.bounds
UIView.animate(withDuration: 0.25) {
self.alpha = 1
self.tableBgView.frame = toFrame
if reloadAlbumList {
if #available(iOS 14.0, *), PHPhotoLibrary.authorizationStatus(for: .readWrite) == .limited {
self.loadAlbumList {
animateShow()
}
} else {
self.loadAlbumList()
animateShow()
}
} else {
animateShow()
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/General/ZLPhotoBrowser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

let version = "4.0.8"
let version = "4.0.9"
4 changes: 2 additions & 2 deletions Sources/General/ZLPhotoConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public class ZLPhotoConfiguration: NSObject {
/// Show the image captured by the camera is displayed on the camera button inside the album.
@objc public var showCaptureImageOnTakePhotoBtn = false

/// In the control single-selection mode, whether to display the selection button, the multi-selection mode is not controlled.
/// In single selection mode, whether to display the selection button.
@objc public var showSelectBtnWhenSingleSelect = false

/// Overlay a mask layer on top of the selected photos.
Expand All @@ -233,7 +233,7 @@ public class ZLPhotoConfiguration: NSObject {
/// Display the selected photos at the bottom of the preview large photos interface.
@objc public var showSelectedPhotoPreview = true

/// Developers can customize pictures, but the name of the custom picture resource must be consistent with the picture name in the replaced bundle.
/// Developers can customize iamges, but the name of the custom image resource must be consistent with the image name in the replaced bundle.
/// - example: Developers need to replace the selected and unselected image resources, and the array that needs to be passed in is
/// ["zl_btn_selected", "zl_btn_unselected"].
@objc public var customImageNames: [String] = [] {
Expand Down
32 changes: 13 additions & 19 deletions Sources/General/ZLPhotoManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Photos

public class ZLPhotoManager: NSObject {

/// save image to album
/// Save image to album.
@objc public class func saveImageToAlbum(image: UIImage, completion: ( (Bool, PHAsset?) -> Void )? ) {
let status = PHPhotoLibrary.authorizationStatus()

Expand All @@ -54,7 +54,7 @@ public class ZLPhotoManager: NSObject {
}
}

/// save video to album
/// Save video to album.
@objc public class func saveVideoToAlbum(url: URL, completion: ( (Bool, PHAsset?) -> Void )? ) {
let status = PHPhotoLibrary.authorizationStatus()

Expand Down Expand Up @@ -90,7 +90,7 @@ public class ZLPhotoManager: NSObject {
return nil
}

/// fetch photos from result
/// Fetch photos from result.
class func fetchPhoto(in result: PHFetchResult<PHAsset>, ascending: Bool, allowSelectImage: Bool, allowSelectVideo: Bool, limitCount: Int = .max) -> [ZLPhotoModel] {
var models: [ZLPhotoModel] = []
let option: NSEnumerationOptions = ascending ? .init(rawValue: 0) : .reverse
Expand All @@ -116,7 +116,7 @@ public class ZLPhotoManager: NSObject {
return models
}

/// fetch all album list
/// Fetch all album list.
class func getPhotoAlbumList(ascending: Bool, allowSelectImage: Bool, allowSelectVideo: Bool, completion: ( ([ZLAlbumListModel]) -> Void )) {
let option = PHFetchOptions()
if !allowSelectImage {
Expand Down Expand Up @@ -150,7 +150,7 @@ public class ZLPhotoManager: NSObject {
let title = self.getCollectionTitle(collection)

if collection.assetCollectionSubtype == .smartAlbumUserLibrary {
// 所有照片
// Album of all photos.
let m = ZLAlbumListModel(title: title, result: result, collection: collection, option: option, isCameraRoll: true)
albumList.insert(m, at: 0)
} else {
Expand All @@ -163,7 +163,7 @@ public class ZLPhotoManager: NSObject {
completion(albumList)
}

/// fetch camera roll album
/// Fetch camera roll album.
class func getCameraRollAlbum(allowSelectImage: Bool, allowSelectVideo: Bool, completion: @escaping ( (ZLAlbumListModel) -> Void )) {
let option = PHFetchOptions()
if !allowSelectImage {
Expand All @@ -184,10 +184,10 @@ public class ZLPhotoManager: NSObject {
}
}

/// conversion collection title
/// Conversion collection title.
private class func getCollectionTitle(_ collection: PHAssetCollection) -> String {
if collection.assetCollectionType == .album {
// 用户创建的相册
// Albums created by user.
var title: String? = nil
if ZLCustomLanguageDeploy.language == .system {
title = collection.localizedTitle
Expand Down Expand Up @@ -255,7 +255,7 @@ public class ZLPhotoManager: NSObject {
return self.fetchImage(for: asset, size: PHImageManagerMaximumSize, resizeMode: .fast, progress: progress, completion: completion)
}

/// fetch asset data
/// Fetch asset data.
@discardableResult
class func fetchOriginalImageData(for asset: PHAsset, progress: ( (CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void )? = nil, completion: @escaping ( (Data, [AnyHashable: Any]?, Bool) -> Void)) -> PHImageRequestID {
let option = PHImageRequestOptions()
Expand All @@ -280,14 +280,9 @@ public class ZLPhotoManager: NSObject {
}
}

/// fetch image for asset
/// Fetch image for asset.
private class func fetchImage(for asset: PHAsset, size: CGSize, resizeMode: PHImageRequestOptionsResizeMode, progress: ( (CGFloat, Error?, UnsafeMutablePointer<ObjCBool>, [AnyHashable : Any]?) -> Void )? = nil, completion: @escaping ( (UIImage?, Bool) -> Void )) -> PHImageRequestID {
let option = PHImageRequestOptions()
/**
resizeMode:对请求的图像怎样缩放。有三种选择:None,默认加载方式;Fast,尽快地提供接近或稍微大于要求的尺寸;Exact,精准提供要求的尺寸。
deliveryMode:图像质量。有三种值:Opportunistic,在速度与质量中均衡;HighQualityFormat,不管花费多长时间,提供高质量图像;FastFormat,以最快速度提供好的质量。
这个属性只有在 synchronous 为 true 时有效。
*/
option.resizeMode = resizeMode
option.isNetworkAccessAllowed = true
option.progressHandler = { (pro, error, stop, info) in
Expand All @@ -306,7 +301,6 @@ public class ZLPhotoManager: NSObject {
completion(image, isDegraded)
}
}

}

class func fetchLivePhoto(for asset: PHAsset, completion: @escaping ( (PHLivePhoto?, [AnyHashable: Any]?, Bool) -> Void )) -> PHImageRequestID {
Expand All @@ -330,7 +324,7 @@ public class ZLPhotoManager: NSObject {
}
}
return PHImageManager.default().requestPlayerItem(forVideo: asset, options: option) { (item, info) in
// iOS11 系统这个回调没有在主线程
// iOS11 and earlier, callback is not on the main thread.
DispatchQueue.main.async {
let isDegraded = (info?[PHImageResultIsDegradedKey] as? Bool ?? false)
completion(item, info, isDegraded)
Expand Down Expand Up @@ -360,7 +354,7 @@ public class ZLPhotoManager: NSObject {
}
}

/// fetch asset local file path
/// Fetch asset local file path.
@objc public class func fetchAssetFilePath(asset: PHAsset, completion: @escaping (String?) -> Void ) {
asset.requestContentEditingInput(with: nil) { (input, info) in
var path = input?.fullSizeImageURL?.absoluteString
Expand All @@ -374,7 +368,7 @@ public class ZLPhotoManager: NSObject {
}


/// authority related
/// Authority related.
extension ZLPhotoManager {

public class func havePhotoLibratyAuthority() -> Bool {
Expand Down
2 changes: 1 addition & 1 deletion Sources/General/ZLPhotoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ZLPhotoModel: NSObject {
}
}

// 保存上次编辑图片的一些内容,下次编辑时候可继续上次的编辑
// Content of the last edit.
var editImageModel: ZLEditImageModel?

init(asset: PHAsset) {
Expand Down
Loading

0 comments on commit ee4b05d

Please sign in to comment.