美文网首页
PhotosKit中类说明

PhotosKit中类说明

作者: 云海绽放 | 来源:发表于2020-12-01 18:41 被阅读0次

PHAsset相册中的资源
PHAssetCollection 相册 是PHAsset的一个集合
PHPhotoLibrary 图库代表整个相册
可以执行一些增删等操作
PHImageManager 访问PHAsset里的真正的图片或者视频
PHAssetChangeRequest 是改变类,需要PHPhotoLibrary去执行
PHCachingImageManager 取资源时的缓存设置

func createAlbum() {
//查找又没有创建"我创建的"这个相册,没有的话再创建 ,遍历的是用户自定义的相册不是智能相册
let result = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: nil)
result.enumerateObjects { (collect, index, stop) in
if collect.localizedTitle == "我创建的" {
stop.pointee = true
}
if index == result.count-1 {
PHPhotoLibrary.shared().performChanges {
PHAssetCollectionChangeRequest.creationRequestForAssetCollection(withTitle: "我创建的")
} completionHandler: { (flag, error) in
print(error)
}
}
}
}

func addPhoto() {
let result = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: nil)
result.enumerateObjects { (collect, index, stop) in
if collect.localizedTitle == "我创建的" {
stop.pointee = true
PHPhotoLibrary.shared().performChanges {
let image = UIImage(named: "home_banner")
PHAssetChangeRequest.creationRequestForAsset(from: image!)
let request = PHAssetCollectionChangeRequest(for: collect)
let placeholder = request?.placeholderForCreatedAssetCollection
request?.addAssets([placeholder] as NSFastEnumeration)
} completionHandler: { (flag, error) in
print(error)
}

        }
    }
}

func deletePhoto() {
let result = PHAssetCollection.fetchAssetCollections(with: .smartAlbum, subtype: .any, options: nil)
result.enumerateObjects { (collect, index, stop) in
if collect.localizedTitle == "我创建的" {
stop.pointee = true
let result = PHAsset.fetchAssets(in: collect, options: nil)
result.enumerateObjects { (asset, index, stop) in

                PHImageManager.default().requestImage(for: asset, targetSize:  CGSize(width: asset.pixelWidth, height: asset.pixelHeight), contentMode: .aspectFill, options: nil) { (image, dict) in
                
                }
                PHPhotoLibrary.shared().performChanges {
                    if index == collect.accessibilityElementCount()-1 {
                        stop.pointee = true
                        PHAssetCollectionChangeRequest.deleteAssetCollections([asset] as NSFastEnumeration)
                    }
                } completionHandler: { (flag, error) in
                    print(error)
                }
            }
        }
    }
}

相关文章

  • PhotosKit中类说明

    PHAsset相册中的资源PHAssetCollection 相册 是PHAsset的一个集合PHPhotoLib...

  • 仿QQ侧滑菜单

    一. 实例说明 二. 关键技术    使用自定义类 QQMenu 类中的构造方法,View类中的 onMeasur...

  • 代码规范

    参考地址 术语说明 在文档中,除非另有说明: 术语 class 可表示一个普通类,枚举类,接口或是annotati...

  • 走近省考英语作文1--“自我介绍”

    福建省中考英语作文,一般分三大类,即说明介绍类、观点建议类和写人叙事类。今天我们来分享一下,说明介绍类中的一...

  • Java编码规范Google版

    1.1 术语说明 在本文档中,除非另有说明: 1、术语class可表示一个普通类,枚举类,接口或是annotati...

  • Day-16 类

    类和对象 class 类名:说明文档方法 - 声明在类中的方法(静态方法 : @staticmethod,...

  • NSURLSessionTask

    NSURLSessionTask 大致说明 NSURLSessionTask类是URL会话中任务的基类。任务总是会...

  • 二、Toolbar

    一、Toolbar类的继承关系: 二、Toolbar中主要功能的说明 三、Toolbar中主要属性的说明 使用To...

  • NSJSONSerialization类中的枚举值说明

    NSJSONReadingOptions: NSJSONReadingMutableContainers:返回可变...

  • CodeSmith中SchemaExplorer类详解说明

    代码生成工具CodeSmith中SchemaExplorer类API文档 SchemaExplorer中主要类的结...

网友评论

      本文标题:PhotosKit中类说明

      本文链接:https://www.haomeiwen.com/subject/hsoswktx.html