MediaUtilities(媒体工具)

此软件包允许你:

安装

Swift Package Manager(Swift 包管理器)

用法

你可以根据需要使用单个文件。 要获得整体统一的方法,请使用

图像

允许裁剪、旋转图像,以及更多功能即将推出。 它还允许从“照片”、“Finder”、“Safari”以及任何可以拖动图像的地方拖放任何图像。

欢迎添加你的实现并提交 PR(Pull Request,拉取请求)。

/// a holistic image picker that allows for picking or dropping image to the attached view and editing the image before retuning the final image.
/// the image editor uses gestures, keep this in mind when attaching this modifier to a sheet, a scrollview or any view with gestures enabled
/// - Parameters:
///   - isPresented: a bool that directly controls the media picker
///   - aspectRatio: desired aspect ratio, when the mash shape is curcular this value is ignored in favour of 1
///   - maskShape: desired mask shape, when you choose circular the aspect ratio is automatically 1
///   - isGuarded: a bool that indicates whether the attached view can accept dropping of images
///   - onCompletion: call back with a result of type `Result<UnifiedImage, Error>`
///
@inlinable public func imagePicker(
    _ isPresented: Binding<Bool>,
    aspectRatio: CGFloat,
    maskShape: MaskShape = .rectangular,
    isGuarded: Binding<Bool>,
    onCompletion: @escaping (Result<UnifiedImage, Error>) -> Void
) -> some View

视频

/// a holistic video picker that allows for picking or dropping of videos or url with videos to the attached view
/// and editing of the video before retuning the url in the local file sytem.
/// internet urls will be downloaded before editing the video.
/// - Parameters:
///   - isPresented: a bool that directly controls the media picker
///   - isGuarded: a bool that indicates whether the attached view can accept dropping of url or video
///   - onCompletion: call back with a result of type `Result<URL, Error>`, the url is a local file url
@inlinable public func videoPicker(
    _ isPresented: Binding<Bool>,
    isGuarded: Binding<Bool>,
    onCompletion: @escaping (Result<URL, Error>) -> Void
) -> some View

它允许你将资源拖放到视图中,编辑资源,然后返回编辑后的资源。 isPresented 直接控制 iOS 中的 PhotosPicker 和 macOS 中的 Finder 窗口。

待办事项

SDK

某些功能可能需要更高的版本。 但一般来说,它支持以下版本:

虽然该软件包主要是为 SwiftUI 编写的,但图像和视频操作可以在 UIKit 和 AppKit 中使用。

代码贡献

欢迎通过 fork/pull request(分支/拉取请求)的方式向 main 分支贡献代码。 如果你想请求一个功能或报告一个错误,请创建一个新的 issue(问题)。

许可协议

MIT