图像坐标空间

用于 UIImageView 图像的 UICoordinateSpace

CI codecov Depfu

Swift Version License Platform Carthage compatible

用法

CGPoint 从图像坐标转换为视图坐标

import ImageCoordinateSpace

let imageSpace = imageView.contentSpace()
let imageTopLeft = imageSpace.convert(CGPoint.zero, to: imageView)

CGPoint 从视图坐标转换为图像坐标

let viewTopLeft = imageSpace.convert(CGPoint.zero, from: imageView)

CGRect 也提供类似的转换

let imageRect = CGRect(x: 321, y: 102, width: 63, height: 64)
let viewRect = imageSpace.convert(imageRect, to: imageView)

以及从视图坐标到图像坐标的转换

let viewRect = CGRect(x: 107, y: 68, width: 21, height: 42.667)
let imageRect = imageSpace.convert(viewRect, from: imageView)

示例

添加定位的图像叠加层

打开包含的 Xcode 示例项目以查看 Xcode Playground:Example/Visual.playground

Demonstrate image ovelay placement

将图像人脸检测区域转换为视图触摸点

来自热门 Stackoverflow 问题的其他用途

文档

包含 HeaderDoc,请参阅 UIImageView+UICoordinateSpace.swift

安装

CocoaPods

pod 'ImageCoordinateSpace'

Carthage

单元测试

要运行包含的单元测试,请通过 Carthage 安装依赖项

carthage bootstrap

运行测试

xcodebuild test -scheme ImageCoordinateSpace -destination 'platform=iOS Simulator,name=iPhone 11 Pro'

观看它们以闪电般的速度通过

Test Suite 'All tests' passed at 2017-12-13 08:07:14.826.
Executed 36 tests, with 0 failures (0 unexpected) in 0.013 (0.023) seconds
** TEST SUCCEEDED **

作者

Paul Zabelin, https://github.com/paulz

许可证

ImageCoordinateSpace 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。