Skip to content

Commit ee4b05d

Browse files
committed
release 4.0.9
1 parent c6baed5 commit ee4b05d

14 files changed

+122
-75
lines changed

Example/Example/ViewController.swift

+19-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ class ViewController: UIViewController {
122122
}
123123

124124
@objc func previewSelectPhoto() {
125-
// ZLPhotoConfiguration.default().editImageClipRatios = [.custom, .wh1x1, .wh3x4, .wh16x9, ZLImageClipRatio(title: "2 : 1", whRatio: 2 / 1)]
126125
let ac = ZLPhotoPreviewSheet(selectedAssets: self.takeSelectedAssetsSwitch.isOn ? self.selectedAssets : [])
127126
ac.selectImageBlock = { [weak self] (images, assets, isOriginal) in
128127
self?.selectedImages = images
@@ -131,19 +130,37 @@ class ViewController: UIViewController {
131130
self?.collectionView.reloadData()
132131
debugPrint("\(images) \(assets) \(isOriginal)")
133132
}
133+
ac.cancelBlock = {
134+
debugPrint("cancel select")
135+
}
136+
ac.selectImageRequestErrorBlock = { (errorAssets, errorIndexs) in
137+
debugPrint("fetch error assets: \(errorAssets), error indexs: \(errorIndexs)")
138+
}
134139
ac.showPreview(animate: true, sender: self)
135140
}
136141

137142
@objc func librarySelectPhoto() {
138143
// ZLPhotoConfiguration.default().editImageClipRatios = [.custom, .wh1x1, .wh3x4, .wh16x9, ZLImageClipRatio(title: "2 : 1", whRatio: 2 / 1)]
139144
// ZLPhotoConfiguration.default().filters = [.normal, .process, ZLFilter(name: "custom", applier: ZLCustomFilter.hazeRemovalFilter)]
145+
146+
// You can first determine whether the asset is allowed to be selected.
147+
ZLPhotoConfiguration.default().canSelectAsset = { (asset) -> Bool in
148+
return true
149+
}
150+
140151
let ac = ZLPhotoPreviewSheet(selectedAssets: self.takeSelectedAssetsSwitch.isOn ? self.selectedAssets : [])
141152
ac.selectImageBlock = { [weak self] (images, assets, isOriginal) in
142153
self?.selectedImages = images
143154
self?.selectedAssets = assets
144155
self?.collectionView.reloadData()
145156
debugPrint("\(images) \(assets) \(isOriginal)")
146157
}
158+
ac.cancelBlock = {
159+
debugPrint("cancel select")
160+
}
161+
ac.selectImageRequestErrorBlock = { (errorAssets, errorIndexs) in
162+
debugPrint("fetch error assets: \(errorAssets), error indexs: \(errorIndexs)")
163+
}
147164
ac.showPhotoLibrary(sender: self)
148165
}
149166

@@ -171,6 +188,7 @@ class ViewController: UIViewController {
171188

172189
let videoSuffixs = ["mp4", "mov", "avi", "rmvb", "rm", "flv", "3gp", "wmv", "vob", "dat", "m4v", "f4v", "mkv"] // and more suffixs
173190
let vc = ZLImagePreviewController(datas: datas, index: 0, showSelectBtn: true) { (url) -> ZLURLType in
191+
// Just for demo.
174192
if url.absoluteString == netVideoUrlString {
175193
return .video
176194
}

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22+

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,17 @@ Detailed usage of `Swift` and `OC`, please refer to [Wiki](https://github.com/lo
8989
### <a id="UpdateLog"></a>Update Log
9090
> [More logs](https://github.com/longitachi/ZLPhotoBrowser/blob/master/UPDATELOG.md)
9191
```
92-
● 4.0.8: Add filter to image editor;
93-
● 4.0.7: Image editor support crop ratios; Custom camera supports switching camera during recording; bug fixed;
94-
● 4.0.5: Support iOS14 limited authority; Optimize picture preview display;
92+
● 4.0.9:
93+
Support languages of more countries (French, German, Russian, Vietnamese, Korean, Malay, Italian).
94+
Support iOS14 limited authority.
95+
Provides the ability to preview PHAsset, local images and videos, network images and videos together.
96+
Optimize some UI effects.
97+
● 4.0.8:
98+
Add filter to image editor.
99+
● 4.0.7:
100+
Image editor support crop ratios.
101+
Custom camera supports switching camera during recording.
102+
bug fixed.
95103
...
96104
```
97105

README_CN.md

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

Sources/General/ZLEmbedAlbumListView.swift

+36-23
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
// THE SOFTWARE.
2626

2727
import UIKit
28+
import Photos
2829

2930
class ZLEmbedAlbumListView: UIView {
3031

@@ -105,13 +106,14 @@ class ZLEmbedAlbumListView: UIView {
105106
self.addGestureRecognizer(tap)
106107
}
107108

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

114115
DispatchQueue.main.async {
116+
completion?()
115117
self?.tableView.reloadData()
116118
}
117119
}
@@ -133,30 +135,41 @@ class ZLEmbedAlbumListView: UIView {
133135

134136
/// 这里不采用监听相册发生变化的方式,是因为每次变化,系统都会回调多次,造成重复获取相册列表
135137
func show(reloadAlbumList: Bool) {
136-
if reloadAlbumList {
137-
self.loadAlbumList()
138-
}
139-
140-
let toFrame = self.calculateBgViewBounds()
141-
142-
self.isHidden = false
143-
self.alpha = 0
144-
var newFrame = toFrame
145-
newFrame.origin.y -= newFrame.height
146-
147-
if newFrame != self.tableBgView.frame {
148-
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: newFrame.width, height: newFrame.height), byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 8, height: 8))
149-
self.tableBgView.layer.mask = nil
150-
let maskLayer = CAShapeLayer()
151-
maskLayer.path = path.cgPath
152-
self.tableBgView.layer.mask = maskLayer
138+
func animateShow() {
139+
let toFrame = self.calculateBgViewBounds()
140+
141+
self.isHidden = false
142+
self.alpha = 0
143+
var newFrame = toFrame
144+
newFrame.origin.y -= newFrame.height
145+
146+
if newFrame != self.tableBgView.frame {
147+
let path = UIBezierPath(roundedRect: CGRect(x: 0, y: 0, width: newFrame.width, height: newFrame.height), byRoundingCorners: [.bottomLeft, .bottomRight], cornerRadii: CGSize(width: 8, height: 8))
148+
self.tableBgView.layer.mask = nil
149+
let maskLayer = CAShapeLayer()
150+
maskLayer.path = path.cgPath
151+
self.tableBgView.layer.mask = maskLayer
152+
}
153+
154+
self.tableBgView.frame = newFrame
155+
self.tableView.frame = self.tableBgView.bounds
156+
UIView.animate(withDuration: 0.25) {
157+
self.alpha = 1
158+
self.tableBgView.frame = toFrame
159+
}
153160
}
154161

155-
self.tableBgView.frame = newFrame
156-
self.tableView.frame = self.tableBgView.bounds
157-
UIView.animate(withDuration: 0.25) {
158-
self.alpha = 1
159-
self.tableBgView.frame = toFrame
162+
if reloadAlbumList {
163+
if #available(iOS 14.0, *), PHPhotoLibrary.authorizationStatus(for: .readWrite) == .limited {
164+
self.loadAlbumList {
165+
animateShow()
166+
}
167+
} else {
168+
self.loadAlbumList()
169+
animateShow()
170+
}
171+
} else {
172+
animateShow()
160173
}
161174
}
162175

Sources/General/ZLPhotoBrowser.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2525
// THE SOFTWARE.
2626

27-
let version = "4.0.8"
27+
let version = "4.0.9"

Sources/General/ZLPhotoConfiguration.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public class ZLPhotoConfiguration: NSObject {
215215
/// Show the image captured by the camera is displayed on the camera button inside the album.
216216
@objc public var showCaptureImageOnTakePhotoBtn = false
217217

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

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

236-
/// Developers can customize pictures, but the name of the custom picture resource must be consistent with the picture name in the replaced bundle.
236+
/// Developers can customize iamges, but the name of the custom image resource must be consistent with the image name in the replaced bundle.
237237
/// - example: Developers need to replace the selected and unselected image resources, and the array that needs to be passed in is
238238
/// ["zl_btn_selected", "zl_btn_unselected"].
239239
@objc public var customImageNames: [String] = [] {

Sources/General/ZLPhotoManager.swift

+13-19
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import Photos
2929

3030
public class ZLPhotoManager: NSObject {
3131

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

@@ -54,7 +54,7 @@ public class ZLPhotoManager: NSObject {
5454
}
5555
}
5656

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

@@ -90,7 +90,7 @@ public class ZLPhotoManager: NSObject {
9090
return nil
9191
}
9292

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

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

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

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

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

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

283-
/// fetch image for asset
283+
/// Fetch image for asset.
284284
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 {
285285
let option = PHImageRequestOptions()
286-
/**
287-
resizeMode:对请求的图像怎样缩放。有三种选择:None,默认加载方式;Fast,尽快地提供接近或稍微大于要求的尺寸;Exact,精准提供要求的尺寸。
288-
deliveryMode:图像质量。有三种值:Opportunistic,在速度与质量中均衡;HighQualityFormat,不管花费多长时间,提供高质量图像;FastFormat,以最快速度提供好的质量。
289-
这个属性只有在 synchronous 为 true 时有效。
290-
*/
291286
option.resizeMode = resizeMode
292287
option.isNetworkAccessAllowed = true
293288
option.progressHandler = { (pro, error, stop, info) in
@@ -306,7 +301,6 @@ public class ZLPhotoManager: NSObject {
306301
completion(image, isDegraded)
307302
}
308303
}
309-
310304
}
311305

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

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

376370

377-
/// authority related
371+
/// Authority related.
378372
extension ZLPhotoManager {
379373

380374
public class func havePhotoLibratyAuthority() -> Bool {

Sources/General/ZLPhotoModel.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class ZLPhotoModel: NSObject {
7878
}
7979
}
8080

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

8484
init(asset: PHAsset) {

0 commit comments

Comments
 (0)