Skip to content

Commit

Permalink
add annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyuexit committed Sep 15, 2017
1 parent 5081b9b commit 2667931
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
21 changes: 7 additions & 14 deletions LPAlbum/Controllers/LPAlbum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,13 @@
// Copyright © 2017年 Loopeer. All rights reserved.
/**
TODO: 1. add CompleteSelectAssetsBlock
2. add Photo Cache
4. 图片详情zoom
5. 选取单个图片的情形
6. 支持裁剪(正方形, 圆形)
7. take photo statusBarAnimation
8. 是否要加Observer, 如果有Observer, 图片添加或者删除了, 要响应的添加或删除该图片的缓存
9. 完善demo(照片墙, 权限跳转)
10. 加一些动画效果
11. 添加注释
12. 是否内部对图片处理画一遍
2. 选取单个图片的情形
3. 支持裁剪(正方形, 圆形)
4. 是否要加Observer, 如果有Observer, 图片添加或者删除了, 要响应的添加或删除该图片的缓存
5. 完善demo(照片墙, 权限跳转)
6. 加一些动画效果
7. 添加注释
8. 是否内部对图片处理画一遍
*/

import UIKit
Expand Down Expand Up @@ -90,10 +87,6 @@ public class LPAlbum: UIViewController {
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

public override func loadView() {
super.loadView()
}

public override func viewDidLoad() {
super.viewDidLoad()
Expand Down
5 changes: 3 additions & 2 deletions LPAlbum/Others/AlbumManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ public class AlbumManager {
static let imageManager = PHCachingImageManager()

public class func getAlbums() -> [AlbumModel] {
//获取智能相册
// 获取智能相册
let smartAlbums = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .albumRegular, options: nil)
//获取用户创建的相册
// 获取用户创建的相册
let userAlbums = PHAssetCollection.fetchTopLevelUserCollections(with: nil)
// 遍历相册
let smartModels = enumerateAlbum(album: smartAlbums as! PHFetchResult<PHCollection>)
let userModels = enumerateAlbum(album: userAlbums)
// 数量排序
return (smartModels + userModels).sorted{ $0.count > $1.count }
}

Expand Down
14 changes: 11 additions & 3 deletions LPAlbum/Others/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,30 @@ import Foundation

public extension LPAlbum {
public struct Config {
/// 最大选择数量
public var maxSelectCount: Int = 6
/// 每列照片数量
public var columnCount: Int = 4
/// 照片间距
public var photoPadding: CGFloat = 2.0
/// 是否有相机
public var hasCamera: Bool = true
public var isSingleSelect: Bool = false
}

public struct Style {

/// `NavigationBar`标题颜色
public static var barTitleColor: UIColor = UIColor.white
/// `NavigationBar`背景颜色
public static var barTintColor: UIColor = UIColor.darkGray
/// `NavigationBar`item文本颜色
public static var tintColor: UIColor = UIColor.white
/// 状态栏样式
public static var statusBarStyle: UIStatusBarStyle = .lightContent

/// 下拉箭头图片
public static var arrowImage: UIImage = Bundle.imageFromBundle("meun_down")!
/// 正常的选择框图片
public static var normalBox: UIImage = Bundle.imageFromBundle("circle_normal")!
/// 选中的选择框图片
public static var selectedBox: UIImage = Bundle.imageFromBundle("circle_selected")!
}

Expand Down
4 changes: 2 additions & 2 deletions LPAlbum/Others/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ extension UIControl {
}

extension String {

/// 是否是有效的相册
var isAvailableAlbum: Bool {
return !(isEmpty || contains("Hidden") || contains("已隐藏") || contains("Deleted") || contains("最近删除"))
}

/// 国际化文本
static func local(_ key: String) -> String {
return Bundle.localizedString(key: key)
}
Expand Down
17 changes: 17 additions & 0 deletions LPAlbum/Others/Models.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,34 @@ import Foundation
import Photos

public struct AssetModel {
/// 照片
var asset: PHAsset
/// 是否被选中
var isSelect: Bool
}

public struct AlbumModel {
/// 相册名字
var name: String
/// 相册封面
var cover: PHAsset
/// 照片数量
var count: Int
/// 照片Model
var assetModels: [AssetModel]
/// 该相册中被选中的数量
var selectCount: Int { return assetModels.filter{ $0.isSelect == true }.count }
}

extension PHAsset {

/// `PHAsset`转变成`AssetModel`
var toAssetModel: AssetModel { return AssetModel(asset: self, isSelect: false) }
}

extension PHFetchResult where ObjectType == PHAsset {

/// `PHFetchResult<PHAsset>`转变成`[AssetModel]`
var toAssetModels: [AssetModel] {
var result = [AssetModel]()
enumerateObjects({ (asset, i, stop) in
Expand All @@ -38,6 +49,10 @@ extension PHFetchResult where ObjectType == PHAsset {

extension Array where Iterator.Element == AlbumModel {

/// 改变AlbumModel数组中的所有assetModel
///
/// - Parameter assetModel: 传入的assetModel
/// - Returns: 改变后的AlbumModel数组
func change(assetModel: AssetModel) -> [AlbumModel] {

return map{
Expand All @@ -49,9 +64,11 @@ extension Array where Iterator.Element == AlbumModel {
}
}

/// 得到相册中所有的不重复的AssetModel
var allSelectedAssetModels: [AssetModel] {
return self[0].assetModels.filter{ $0.isSelect == true }
}
/// 得到所有的选中的`PHAsset`
var allSelectedAsset: [PHAsset] {
return allSelectedAssetModels.map{ $0.asset }
}
Expand Down

0 comments on commit 2667931

Please sign in to comment.