管理CGPoints, CGSizes CGVectors - CGOperators

2017-07-15      93      Swift
项目简介

Welcome toCGOperators, a small Swift framework that enables you to easily manipulate Core Graphics' vector types (CGPoint,CGSizeandCGVector) using math operators. It can help you write compact, yet highly readable code when dealing with things like image sizes and frame-based layouts.

Examples

Add two vectors

let point = view.frame.origin + CGPoint(x: 10, y: 20)
let size = image.size + view.frame.size
let vector = physicsWorld.gravity + player.size

Subtract two vectors

let point = view.frame.origin - CGPoint(x: 10, y: 20)
let size = image.size - view.frame.size
let vector = physicsWorld.gravity - player.size

Multiply a vector with a constant

view.frame.size = image.size * 4
button.frame.origin = superview.bounds.size * 2
physicsWorld.gravity = player.position * 10

Divide a vector by a constant

view.frame.size = image.size / 4
button.frame.origin = superview.bounds.size / 2
physicsWorld.gravity = player.position / 10

Installation

Using CocoaPods

Addpod CGOperatorsto yourPodfile