Swiftpack.co - Lebron1992/LBJImagePreviewer as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Lebron1992/LBJImagePreviewer
LBJImagePreviewer 是一个在 SwiftUI 框架下实现的图片预览器。(LBJImagePreviewer is an image previewer implemented with SwiftUI.)
.package(url: "https://github.com/Lebron1992/LBJImagePreviewer.git", from: "1.0.0")

LBJImagePreviewer

English Readme

LBJImagePreviewer 是一个在 SwiftUI 框架下实现的图片预览器。

特性

  • 手势缩放和滚动
  • 双击放大缩小

预览

preview

安装

使用 Swift Package Manager 安装:

  1. 复制库的路径
https://github.com/Lebron1992/LBJImagePreviewer
  1. 在 Xcode 中打开菜单 File / Add Packages
  2. 把路径粘贴到搜索框,根据提示把库添加到项目中

使用

UIImage

预览 UIImage

let uiImage = UIImage(named: "lebron")!
LBJUIImagePreviewer(uiImage: uiImage)

Image

预览 Image

// 需要传入 `Image` 的宽高比
LBJImagePreviewer(content: Image(uiImage: uiImage), aspectRatio: 2 / 3)

任意 View

如果你不是直接通过 UIImage 或者 Image 来显示图片,你可以预览任意 View。例如预览一个红色背景:

LBJViewZoomer<Color>(content: .red, aspectRatio: 1)

指定双击时的放大倍数

指定当用户双击图片时的放大倍数,默认是 3

LBJUIImagePreviewer(uiImage: uiImage, doubleTapScale: 5)
LBJImagePreviewer(content: Image(uiImage: uiImage), aspectRatio: 2 / 3, doubleTapScale: 5)

指定最大放大倍数

指定最大放大倍数,默认是 16

LBJUIImagePreviewer(uiImage: uiImage, maxScale: 20)
LBJImagePreviewer(content: Image(uiImage: uiImage), aspectRatio: 2 / 3, maxScale: 20)

消失时是否重置倍数

设置消失时是否重置倍数,默认是 true

LBJUIImagePreviewer(uiImage: uiImage, maxScale: 20)
  .resetScaleOnDisappear(true)
LBJImagePreviewer(content: Image(uiImage: uiImage), aspectRatio: 2 / 3, maxScale: 20)
  .resetScaleOnDisappear(false)

存在问题

  • 双击放大时,图片只能从中间位置放大,无法在点击位置放大。(目前 ScrollView 无法手动设置 contentOffset,等待 ScrollView 更新以解决这个问题。)

请求添加新功能

请使用 GitHub issues。

GitHub

link
Stars: 0
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics