Giter Site home page Giter Site logo

photopicker_swiftui's Introduction

PhotoPicker_SwiftUI

SPM Xcode 14.0+ iOS 14.0+ Swift 5.0+ SwiftUI 3.0+

例子

SwiftUI封装完相册后当用户手机内相册存储的照片视频达到一定的数量及(例如150G以上,两万张照片视频左右),LazyVGrid就会陷入一个运算艰难的境地,CPU占用居高不下,暂时没找到很好的优化办法,所以就用UIKit又封装了一遍,看实际需求酌情使用,UIKit封装地址Demo.

可选相册,可预览编辑Gif Video Image Live Photo,透明图片可调整背景色方便编辑

打开使用SwiftUI封装的相册

                Button {
                    isPresentedGallery.toggle()
                } label: {
                    Text("打开自定义相册SwiftUI")
                        .foregroundColor(Color.red)
                        .frame(height: 50)
                }
                .galleryPicker(isPresented: $isPresentedGallery,
                               maxSelectionCount: 7,
                               selectTitle: "Videos",
                               autoCrop: true,
                               cropRatio: .init(width: 1, height: 1),
                               onlyImage: false,
                               selected: $selectItem.pictures)

打开系统相册

                Button {
                    showPicker.toggle()
                } label: {
                    Text("打开系统相册")
                }
                .photoPicker(isPresented: $showPicker,
                             selected: $selectedItems,
                             maxSelectionCount: 5,
                             matching: .any(of: [.images, .livePhotos, .videos]))
                .onChange(of: selectedItems) { newItems in
                    var images = [UIImage]()
                    Task{
                        for item in newItems{
                            if let image = try await item.loadTransfer(type: UIImage.self){
                                images.append(image)
                            }
                        }
                        await MainActor.run {
                            selectedImages = images
                        }
                    }
                }

进入照片视频编辑工具

        .editPicker(isPresented: $isPresentedCrop,
                    cropRatio: .init(width: 10, height: 1),
                    asset: selectItem.selectedAsset) { asset in
            selectItem.pictures.replaceSubrange(selectItem.selectedIndex...selectItem.selectedIndex, with: [asset])
        }

用法

安装

在 Xcode 的菜单栏中选择 File > Swift Packages > Add Pacakage Dependency,然后在搜索栏输入

https://github.com/jackiehu/PhotoPicker_SwiftUI

手动集成

PhotoPicker_SwiftUI 也支持手动集成,只需把Sources文件夹中的PhotoPicker_SwiftUI文件夹拖进需要集成的项目即可

作者

hu,

更多砖块工具加速APP开发

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

ReadMe Card

许可

PhotoPicker_SwiftUI is available under the MIT license. See the LICENSE file for more info.

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.