CocoaPods trunk is moving to be read-only. Read more on the blog, there are 12 months to go.
| TestsTested | ā |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | May 2016 |
| SPMSupports SPM | ā |
Maintained by Jeff Hurray.
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).CATransform
Transform.swift exposes 3 enums, Transform, Transform3D, and 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) M_PI definitions from Darwin.C.Math .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)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) -> CGPointReturns the underlying CGAffineTransform
public var CGATransform: CGAffineTransform { get }.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)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 let inverted = t.inverted let isIdentity = t.isIdentity let scaleAndMove = .Scale(sx: 0.5, sy:1).concat(.Translate(tx: 40, ty: -100)) == Equality Bool Transform == Transform Transform == CGAffineTransform Transform3D == Transform3D Transform3D == CATransform3D + Additive Transform + Transform CGAffineTransform + CGAffineTransform Transform3D + Transform3D CATransform3D + CATransform3D += Assignment Transform += Transform CGAffineTransform += Transform Transform3D += Transform3D CATransform3D += Transform3D <- Assignment CGAffineTransform <- Transform CATransform3D <- Transform3D = operator.2 Variables have been added to UIView to add settable and gettable interfaces for Transform and Transform3D.
var affineTransform: Transform
var transform3D: Transform3DFeel 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.
If you want to add functionality please open an issue and/or create a pull request.
Transform.swift is available under the MIT license. See the LICENSE file for more information.