Latest 0.1.2
Homepage https://github.com/jhurray/Transform.swift
License MIT
Platforms ios 8.0, tvos 9.0, requires ARC
Authors

Transform.swift offers a Swiftier API for applying transforms to UIView and its subclasses.

let scale = Transform.Scale(sx: 0.5, sy: 0.5)
let rotate = Transform.Rotate(rotation: .Degrees(45))
let scaleAndRotate = scale + rotate
myView.transform += scaleAndRotate

myView.transform3D = .Translate(tx: 40, ty: 0, tz: 100)

Installation

CocoaPods

Add the following to your Podfile:

use_frameworks!

pod 'Transform.swift', '~> 0.1.2'

Carthage

Add the following to your Cartfile:

gitub "jhurray/Transform.swift" ~> 0.1.2

Usage

Transform.swift exposes 3 enums, Transform, Transform3D, and Rotation.

Rotation

A convenience enum that allows the developer to easily define the rotation they want. The cases are pretty self explanitory.

  • .Degrees(degrees: CGFloat)
  • .Radians(radians: Double)
    • Takes a double to make it easier to pass the M_PI definitions from Darwin.C.Math

Transform

  • .Identity
  • .Translate(tx: CGFloat, ty: CGFloat)
  • .Scale(sx: CGFloat, sy: CGFloat)
  • .Rotate(rotation: Rotation)
  • .Init(a: CGFloat, b: CGFloat, c: CGFloat, d: CGFloat, tx: CGFloat, ty: CGFloat) for the adventurous type 😎
  • .Custom(t: CGAffineTransform)

Methods

A group of methods that calculate how the transform affects a CGRect, CGSize, and CGPoint respectively.

public func transformedRect(rect: CGRect) -> CGRect
public func transformedSize(size: CGSize) -> CGSize
public func transformedPoint(point: CGPoint) -> CGPoint

Returns the underlying CGAffineTransform

public var CGATransform: CGAffineTransform { get }

Transform3D

  • .Identity
  • .Translate(tx: CGFloat, ty: CGFloat, tz: CGFloat)
  • .Scale(sx: CGFloat, sy: CGFloat, sz: CGFloat)
  • .Rotate(rotation: Rotation, x: CGFloat, y: CGFloat, z: CGFloat)
  • .Affine(t: CGAffineTransform)
  • .Custom(t: CATransform3D)

Methods

Returns the underlying CATransform3D

public var CATransform : CATransform3D { get }

Returns a true if the 3d transform can be converted into an affine transform, false if it cannot.

public var isAffine: Bool { get }

Returns the underlying CGAffineTransform. Will throw an error if the 3D transform cannot be converted into an affine transform.

public func affineTransform() throws -> CGAffineTransform 

Shared Utilities

  • Inverting: let inverted = t.inverted
  • Identity Conformation: let isIdentity = t.isIdentity
  • Concatenation: let scaleAndMove = scale.concat(.Translate(tx: 40, ty: -100))

Operators

  • == Equality
    • Returns Bool
    • Transform == Transform
    • Transform == CGAffineTransform
    • Transform3D == Transform3D
    • Transform3D == CATransform3D
  • + Additive
    • Returns the type being added
    • Transform + Transform
    • CGAffineTransform + CGAffineTransform
    • Transform3D + Transform3D
    • CATransform3D + CATransform3D
  • += Assignment
    • Modifies the left variable of the operator
    • Transform += Transform
    • CGAffineTransform += Transform
    • Transform3D += Transform3D
    • CATransform3D += Transform3D
  • <- Assignment
    • Assigns a value to the left variable of the operator
    • CGAffineTransform <- Transform
    • CATransform3D <- Transform3D
    • Semantics to assign the transform enum to the old API since you cant overload the = operator.

UIView Extension

2 Variables have been added to UIView to add settable and gettable interfaces for Transform and Transform3D.

var affineTransform: Transform
var transform3D: Transform3D

Contact Info

Feel free to email me at [email protected]. I’d love to hear your thoughts on this, or see examples where this has been used.

You can also hit me up on twitter @JeffHurray.

Contributing

If you want to add functionality please open an issue and/or create a pull request.

License

Transform.swift is available under the MIT license. See the LICENSE file for more information.

Latest podspec

{
    "name": "Transform.swift",
    "version": "0.1.2",
    "summary": "A Swiftier way to transform UIView and its subclasses.",
    "homepage": "https://github.com/jhurray/Transform.swift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Jeff Hurray": "[email protected]"
    },
    "source": {
        "git": "https://github.com/jhurray/Transform.swift.git",
        "tag": "0.1.2"
    },
    "social_media_url": "http://twitter.com/JeffHurray",
    "requires_arc": true,
    "source_files": "Transform/*.{h,swift}",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0"
    }
}

Pin It on Pinterest

Share This