Skip to content
UICoordinateSpace for UIImageView image
Swift Ruby Objective-C
Branch: master
Clone or download
Pull request Compare This branch is even with paulz:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
Acceptance Tests
Example
ImageCoordinateSpace.xcodeproj
ImageCoordinateSpace
Unit Tests
.gitignore
.ruby-gemset
.ruby-version
.travis.yml
CHANGELOG.md
Cartfile.private
Cartfile.resolved
Gemfile
Gemfile.lock
ImageCoordinateSpace.podspec
LICENSE
Package.resolved
Package.swift
README.md

README.md

Image Coordinate Space

UICoordinateSpace for UIImageView image

Build Status codecov Depfu

Swift Version License Platform Carthage compatible

Usage

Convert CGPoint from image coordinates to view coordinates:

import ImageCoordinateSpace

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

Convert CGPoint from view coordinates to image coordinates:

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

Similar conversions are available for CGRect:

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

and from view coordinates to image coordinates:

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

Examples

Add positioned image overlay

Open included Xcode Example project to see Xcode Playground: Example/Visual.playground

Demonstrate image ovelay placement

Converting image face detection regions to view touch points

Other uses from popular Stackoverflow questions:

Documentation

HeaderDoc is included, see UIImageView+UICoordinateSpace.swift

Installation

CocoaPods

  • add the following line to your Podfile:

pod 'ImageCoordinateSpace'

  • run pod install

Carthage

  • add to your Cartfile:

    github "paulz/ImageCoordinateSpace"

  • run carthage update

  • link your app with ImageCoordinateSpace.framework from Carthage/Build/iOS folder

Unit tests

To run included unit tests install dependencies via Carthage:

carthage bootstrap

Run tests:

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

See them pass at lightning speed:

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 **

Author

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

License

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

You can’t perform that action at this time.