Giter VIP home page Giter VIP logo

hxphpicker's Introduction

中文 | English

一款图片/视频选择器-支持LivePhoto、GIF选择、iCloud/网络资源在线下载、图片/视频编辑

功能

  • UI 外观支持浅色/深色/自动/自定义
  • 支持多选/混合内容选择
  • 支持的媒体类型:
    • Photo
    • GIF
    • Live Photo
    • Video
  • 支持的本地资源类型:
    • Photo
    • Video
    • GIF
    • Live Photo
  • 支持的网络资源类型:
    • Photo
    • Video
  • 支持下载iCloud上的资源
  • 支持手势返回
  • 支持滑动选择
  • 编辑图片(支持动图、网络资源)
    • 涂鸦
    • 贴纸
    • 文字
    • 裁剪
    • 旋转任意角度
    • 自定义蒙版
    • 马赛克
    • 画面调整
    • 滤镜
  • 编辑视频(支持网络资源)
    • 涂鸦
    • 贴纸(支持GIF)
    • 文字
    • 配乐(支持歌词字幕)
    • 裁剪时长
    • 裁剪尺寸
    • 旋转任意角度
    • 自定义蒙版
    • 画面调整
    • 滤镜
  • 相册展现方式
    • 单独列表
    • 弹窗
  • 多平台支持
    • iOS
    • iPadOS
  • 国际化支持
    • 🇨🇳 简体中文 (zh-Hans)
    • 🇨🇳 繁体中文 (zh-Hant)
    • 🇬🇧 英文 (en)
    • 🇯🇵 日语 (ja)
    • 🇰🇷 韩语 (ko)
    • 🇹🇭 泰语 (th)
    • 🇮🇳 印尼语 (id)
    • 🇻🇳 越南语 (vi)
    • 🇷🇺 俄罗斯 (ru)
    • 🇩🇪 德国 (de)
    • 🇫🇷 法国 (fr)
    • 🇸🇦 阿拉伯 (ar)
    • ✍️ 自定义语言 (custom)
    • 🤝 更多支持... (欢迎PR)

要求

  • iOS 12.0+
  • Xcode 12.5+
  • Swift 5.4+

安装

⚠️ 需要 Xcode 12.0 及以上版本来支持资源文件/本地化文件的添加。

dependencies: [
    .package(url: "https://github.com/SilenceLove/HXPHPicker.git", .upToNextMajor(from: "2.0.0"))
]

将下面内容添加到 Podfile,并执行依赖更新。

iOS 12.0+
pod 'HXPHPicker'

/// 不包含 Kingfisher,相机不包含定位功能
pod `HXPHPicker/Lite`

/// 相机不包含定位功能
pod `HXPHPicker/NoLocation`

/// 只有选择器
pod `HXPHPicker/Picker`
pod `HXPHPicker/Picker/Lite`

/// 只有编辑器
pod `HXPHPicker/Editor`
pod `HXPHPicker/Editor/Lite`

/// 只有相机
pod `HXPHPicker/Camera`
/// 不包含定位功能
pod `HXPHPicker/Camera/Lite`

iOS 10.0+
pod 'HXPHPicker-Lite'
pod 'HXPHPicker-Lite/Picker'
pod 'HXPHPicker-Lite/Editor'
pod 'HXPHPicker-Lite/Camera'

将下面内容添加到 Cartfile,并执行依赖更新。

github "SilenceLove/HXPHPicker"

使用方法

Wiki 中提供了更详细的使用说明。

准备工作

按需在你的 Info.plist 中添加以下键值:

Key 模块 备注
NSPhotoLibraryUsageDescription Picker 允许访问相册
NSPhotoLibraryAddUsageDescription Picker 允许保存图片至相册
PHPhotoLibraryPreventAutomaticLimitedAccessAlert Picker 设置为 YES iOS 14+ 以禁用自动弹出添加更多照片的弹框(Picker 已适配 Limited 功能,可由用户主动触发,提升用户体验)
NSCameraUsageDescription Camera 允许使用相机
NSMicrophoneUsageDescription Camera 允许使用麦克风

快速上手

import HXPHPicker

class ViewController: UIViewController {

    func presentPickerController() {
        // 设置与微信主题一致的配置
        let config = PickerConfiguration.default
        
        // 方法一:
        let pickerController = PhotoPickerController(picker: config)
        pickerController.pickerDelegate = self
        // 当前被选择的资源对应的 PhotoAsset 对象数组
        pickerController.selectedAssetArray = selectedAssets 
        // 是否选中原图
        pickerController.isOriginal = isOriginal
        present(pickerController, animated: true, completion: nil)
        
        // 方法二:
        Photo.picker(
            config
        ) { result, pickerController in
            // 选择完成的回调
            // result 选择结果
            //  .photoAssets 当前选择的数据
            //  .isOriginal 是否选中了原图
            // photoPickerController 对应的照片选择控制器
        } cancel: { pickerController in
            // 取消的回调
            // photoPickerController 对应的照片选择控制器 
        }
    }
}

extension ViewController: PhotoPickerControllerDelegate {
    
    /// 选择完成之后调用
    /// - Parameters:
    ///   - pickerController: 对应的 PhotoPickerController
    ///   - result: 选择的结果
    ///     result.photoAssets  选择的资源数组
    ///     result.isOriginal   是否选中原图
    func pickerController(_ pickerController: PhotoPickerController, 
                            didFinishSelection result: PickerResult) {
        result.getImage { (image, photoAsset, index) in
            if let image = image {
                print("success", image)
            }else {
                print("failed")
            }
        } completionHandler: { (images) in
            print(images)
        }
    }
    
    /// 点击取消时调用
    /// - Parameter pickerController: 对应的 PhotoPickerController
    func pickerController(didCancel pickerController: PhotoPickerController) {
        
    }
}

如何获取

获取 UIImage

/// 如果为视频的话获取则是视频封面
/// compressionQuality: 压缩参数,不传则不压缩 
photoAsset.getImage(compressionQuality: compressionQuality) { image in
    print(image)
}

获取 URL

/// compression: 压缩参数,不传则不压缩
photoAsset.getURL(compression: compression) { result in
    switch result {
    case .success(let urlResult):
        // 媒体类型
        switch urlResult.mediaType {
        case .photo:
            // 图片
        case .video:
            // 视频
        }
        
        // url类型
        switch urlResult.urlType {
        case .local:
            // 本地URL
        case .network:
            // 网络URL
        }
        
        // 获取的地址
        print(urlResult.url)
        
        // LivePhoto 里面包含的 图片和视频 url
        print(urlResult.livePhoto) 
        
    case .failure(let error):
        print(error)
    }
}

更新日志

版本 发布时间 Xcode Swift iOS
v2.0.0 2023-06-14 14.3.0 5.7.0 12.0+
v1.4.6 2022-11-20 14.0.0 5.7.0 12.0+

版权协议

HXPHPicker 基于 MIT 协议进行分发和使用,更多信息参见协议文件

支持

Buy Me A Coffee

Stargazers over time

🔝回到顶部

hxphpicker's People

Contributors

silencelove avatar mohamedabdelmaksoud22 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.