├── .gitignore ├── .swift-version ├── .travis.yml ├── Canvas+.podspec ├── Canvas ├── Assets │ └── .gitkeep └── Classes │ ├── .gitkeep │ ├── Brush.swift │ ├── CGPoint+RelativeLocation.swift │ ├── Canvas+Color.swift │ ├── Canvas+Layers.swift │ ├── Canvas+Other.swift │ ├── Canvas+Paths.swift │ ├── Canvas+Touch.swift │ ├── Canvas.swift │ ├── CanvasEvents.swift │ ├── CanvasLayer.swift │ ├── Enums.swift │ ├── Helpers.swift │ ├── Node.swift │ ├── UIColor+RGB.swift │ ├── UIImage+Properties.swift │ ├── UITouch+Translation.swift │ └── UndoRedoManager.swift ├── CanvasLogo.png ├── Example ├── Canvas.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ └── contents.xcworkspacedata │ └── xcshareddata │ │ └── xcschemes │ │ └── Canvas-Example.xcscheme ├── Canvas.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist ├── Canvas │ ├── AppDelegate.swift │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Info.plist │ └── ViewController.swift ├── Podfile ├── Podfile.lock ├── Pods │ ├── Local Podspecs │ │ └── Canvas.podspec.json │ ├── Manifest.lock │ ├── Pods.xcodeproj │ │ ├── project.pbxproj │ │ └── project.xcworkspace │ │ │ ├── contents.xcworkspacedata │ │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── Target Support Files │ │ ├── Canvas │ │ ├── Canvas-dummy.m │ │ ├── Canvas-prefix.pch │ │ ├── Canvas-umbrella.h │ │ ├── Canvas.modulemap │ │ ├── Canvas.xcconfig │ │ └── Info.plist │ │ ├── Pods-Canvas_Example │ │ ├── Info.plist │ │ ├── Pods-Canvas_Example-acknowledgements.markdown │ │ ├── Pods-Canvas_Example-acknowledgements.plist │ │ ├── Pods-Canvas_Example-dummy.m │ │ ├── Pods-Canvas_Example-frameworks.sh │ │ ├── Pods-Canvas_Example-resources.sh │ │ ├── Pods-Canvas_Example-umbrella.h │ │ ├── Pods-Canvas_Example.debug.xcconfig │ │ ├── Pods-Canvas_Example.modulemap │ │ └── Pods-Canvas_Example.release.xcconfig │ │ └── Pods-Canvas_Tests │ │ ├── Info.plist │ │ ├── Pods-Canvas_Tests-acknowledgements.markdown │ │ ├── Pods-Canvas_Tests-acknowledgements.plist │ │ ├── Pods-Canvas_Tests-dummy.m │ │ ├── Pods-Canvas_Tests-frameworks.sh │ │ ├── Pods-Canvas_Tests-resources.sh │ │ ├── Pods-Canvas_Tests-umbrella.h │ │ ├── Pods-Canvas_Tests.debug.xcconfig │ │ ├── Pods-Canvas_Tests.modulemap │ │ └── Pods-Canvas_Tests.release.xcconfig └── Tests │ ├── Info.plist │ └── Tests.swift ├── LICENSE ├── README.md └── _Pods.xcodeproj /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata/ 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # Bundler 23 | .bundle 24 | 25 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 26 | # Carthage/Checkouts 27 | 28 | Carthage/Build 29 | 30 | # We recommend against adding the Pods directory to your .gitignore. However 31 | # you should judge for yourself, the pros and cons are mentioned at: 32 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 33 | # 34 | # Note: if you ignore the Pods directory, make sure to uncomment 35 | # `pod install` in .travis.yml 36 | # 37 | # Pods/ 38 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 4.2 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # references: 2 | # * http://www.objc.io/issue-6/travis-ci.html 3 | # * https://github.com/supermarin/xcpretty#usage 4 | 5 | osx_image: xcode7.3 6 | language: objective-c 7 | # cache: cocoapods 8 | # podfile: Example/Podfile 9 | # before_install: 10 | # - gem install cocoapods # Since Travis is not always on latest version 11 | # - pod install --project-directory=Example 12 | script: 13 | - set -o pipefail && xcodebuild test -enableCodeCoverage YES -workspace Example/Canvas.xcworkspace -scheme Canvas-Example -sdk iphonesimulator9.3 ONLY_ACTIVE_ARCH=NO | xcpretty 14 | - pod lib lint 15 | -------------------------------------------------------------------------------- /Canvas+.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint Canvas.podspec' to ensure this is a 3 | # valid spec before submitting. 4 | # 5 | # Any lines starting with a # are optional, but their use is encouraged 6 | # To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = 'Canvas+' 11 | s.version = '3.0.6' 12 | s.summary = 'A customizable painting canvas for iOS applications.' 13 | 14 | # This description is used to generate tags and improve search results. 15 | # * Think: What does it do? Why did you write it? What is the focus? 16 | # * Try to keep it short, snappy and to the point. 17 | # * Write the description between the DESC delimiters below. 18 | # * Finally, don't worry about the indent, CocoaPods strips it! 19 | 20 | s.description = <<-DESC 21 | Canvas creates an area on the screen where the user can draw lines and shapes, style drawings by adding different types of brushes, and work with multiple layers. It provides an easy way to add on-screen drawing to any iOS app. 22 | DESC 23 | 24 | s.homepage = 'https://github.com/authman2/Canvas' 25 | # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' 26 | s.license = { :type => 'MIT', :file => 'LICENSE' } 27 | s.author = { 'authman2' => 'authman2@gmail.com' } 28 | s.source = { :git => 'https://github.com/authman2/Canvas.git', :tag => s.version.to_s } 29 | # s.social_media_url = 'https://twitter.com/' 30 | 31 | s.ios.deployment_target = '12.0' 32 | 33 | s.source_files = 'Canvas/Classes/**/*' 34 | 35 | # s.resource_bundles = { 36 | # 'Canvas' => ['Canvas/Assets/*.png'] 37 | # } 38 | 39 | # s.public_header_files = 'Pod/Classes/**/*.h' 40 | # s.frameworks = 'UIKit', 'MapKit' 41 | # s.dependency 'AFNetworking', '~> 2.3' 42 | end 43 | -------------------------------------------------------------------------------- /Canvas/Assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Authman2/Canvas/642de2c90ac457132185039db2552bd47af38791/Canvas/Assets/.gitkeep -------------------------------------------------------------------------------- /Canvas/Classes/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Authman2/Canvas/642de2c90ac457132185039db2552bd47af38791/Canvas/Classes/.gitkeep -------------------------------------------------------------------------------- /Canvas/Classes/Brush.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Brush.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 10/8/18. 6 | // 7 | 8 | import Foundation 9 | 10 | /** A Brush defines the styling for how things should be drawn on the canvas. */ 11 | public struct Brush: Codable { 12 | 13 | /************************ 14 | * * 15 | * VARIABLES * 16 | * * 17 | ************************/ 18 | 19 | /** The stroke color of the brush. */ 20 | public var strokeColor: UIColor 21 | 22 | /** The fill color of the brush. */ 23 | public var fillColor: UIColor? 24 | 25 | /** The thickness of the brush. */ 26 | public var thickness: CGFloat 27 | 28 | /** The opacity of the brush. Between 0 and 1. */ 29 | public var opacity: CGFloat { 30 | didSet { 31 | if opacity > 1 { opacity = 1 } 32 | else if opacity < 0 { opacity = 0 } 33 | } 34 | } 35 | 36 | /** The miter limit of the brush. */ 37 | public var miter: CGFloat { 38 | didSet { 39 | if miter > 1 { miter = 1 } 40 | else if miter < 0 { miter = 0 } 41 | } 42 | } 43 | 44 | /** The shape of the cap of the brush. */ 45 | public var shape: CGLineCap 46 | 47 | /** The line join style. */ 48 | public var joinStyle: CGLineJoin 49 | 50 | 51 | 52 | 53 | /** A default Brush to use. */ 54 | public static let Default: Brush = { 55 | var a = Brush() 56 | a.strokeColor = .black 57 | a.fillColor = nil 58 | a.thickness = 5 59 | a.opacity = 1 60 | a.miter = 1 61 | a.shape = CGLineCap.round 62 | a.joinStyle = CGLineJoin.round 63 | 64 | return a 65 | }() 66 | 67 | 68 | 69 | 70 | 71 | /************************ 72 | * * 73 | * INIT * 74 | * * 75 | ************************/ 76 | 77 | public init(from decoder: Decoder) throws { 78 | let container = try? decoder.container(keyedBy: BrushCodingKeys.self) 79 | thickness = try container?.decodeIfPresent(CGFloat.self, forKey: BrushCodingKeys.thickness) ?? 5 80 | opacity = try container?.decodeIfPresent(CGFloat.self, forKey: BrushCodingKeys.opacity) ?? 1 81 | miter = try container?.decodeIfPresent(CGFloat.self, forKey: BrushCodingKeys.miter) ?? 1 82 | shape = CGLineCap(rawValue: try container?.decodeIfPresent(Int32.self, forKey: BrushCodingKeys.shape) ?? 1) ?? .round 83 | joinStyle = CGLineJoin(rawValue: try container?.decodeIfPresent(Int32.self, forKey: BrushCodingKeys.join) ?? 1) ?? .round 84 | 85 | let sc = try container?.decodeIfPresent([CGFloat].self, forKey: BrushCodingKeys.strokeColor) ?? [0,0,0,1] 86 | let fc = try container?.decodeIfPresent([CGFloat].self, forKey: BrushCodingKeys.fillColor) ?? nil 87 | 88 | strokeColor = UIColor(red: sc[0]/255, green: sc[1]/255, blue: sc[2]/255, alpha: sc[3]) 89 | if fc != nil { fillColor = UIColor(red: fc![0]/255, green: fc![1]/255, blue: fc![2]/255, alpha: fc![3]) } 90 | else { fillColor = nil } 91 | } 92 | 93 | /** Creates a basic Brush that is colored black, has a thickness of 2, and a round line cap. */ 94 | public init() { 95 | strokeColor = UIColor.black 96 | fillColor = nil 97 | thickness = 2 98 | opacity = 1 99 | miter = 1 100 | shape = CGLineCap.round 101 | joinStyle = CGLineJoin.round 102 | } 103 | 104 | 105 | 106 | 107 | /************************ 108 | * * 109 | * FUNCTIONS * 110 | * * 111 | ************************/ 112 | 113 | public func encode(to encoder: Encoder) throws { 114 | var container = encoder.container(keyedBy: BrushCodingKeys.self) 115 | try container.encode(strokeColor.rgba, forKey: BrushCodingKeys.strokeColor) 116 | if fillColor != nil { try container.encode(fillColor!.rgba, forKey: BrushCodingKeys.fillColor) } 117 | try container.encode(thickness, forKey: BrushCodingKeys.thickness) 118 | try container.encode(opacity, forKey: BrushCodingKeys.opacity) 119 | try container.encode(miter, forKey: BrushCodingKeys.miter) 120 | try container.encode(shape.rawValue, forKey: BrushCodingKeys.shape) 121 | try container.encode(joinStyle.rawValue, forKey: BrushCodingKeys.join) 122 | } 123 | 124 | } 125 | -------------------------------------------------------------------------------- /Canvas/Classes/CGPoint+RelativeLocation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // CGPoint+RelativeLocation.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 10/31/18. 6 | // 7 | 8 | import Foundation 9 | 10 | public extension CGPoint { 11 | 12 | /** Returns the relative location of point a in comparison to point b. */ 13 | public func location(inRelationTo b: CGPoint) -> RelativePointPosition { 14 | var rpl: RelativePointPosition = .upperRight 15 | let a: CGPoint = self 16 | 17 | if a.x >= b.x && a.y >= b.y { 18 | rpl = .lowerRight 19 | } else if a.x < b.x && a.y >= b.y { 20 | rpl = .lowerLeft 21 | } else if a.x >= b.x && a.y < b.y { 22 | rpl = .upperRight 23 | } else if a.x < b.x && a.y < b.y { 24 | rpl = .upperLeft 25 | } 26 | 27 | return rpl 28 | } 29 | 30 | 31 | func distance(to: CGPoint) -> CGFloat { 32 | let xComp = (to.x - x) ** 2 33 | let yComp = (to.y - y) ** 2 34 | return sqrt(xComp + yComp) 35 | } 36 | 37 | 38 | /** Returns whether or not this point is within the range of another point. */ 39 | public func inRange(of: CGPoint, by range: CGFloat) -> Bool { 40 | let dist = self.distance(to: of) 41 | return dist <= range 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Canvas/Classes/Canvas+Color.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Canvas+Color.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 11/1/18. 6 | // 7 | 8 | import Foundation 9 | 10 | public extension Canvas { 11 | 12 | /** Handles grabbing a color from an area on the canvas. */ 13 | func handleEyedrop(point: CGPoint) { 14 | // Only track the eyedropper on the canvas. 15 | if hitTest(point, with: nil) != self { return } 16 | 17 | let colorSpace = CGColorSpaceCreateDeviceRGB() 18 | let bitmap = CGBitmapInfo.init(rawValue: CGImageAlphaInfo.premultipliedLast.rawValue) 19 | var pixels: [UInt8] = [0,0,0,0] 20 | 21 | if let context = CGContext(data: &pixels, width: 1, height: 1, bitsPerComponent: 8, bytesPerRow: 4, space: colorSpace, bitmapInfo: bitmap.rawValue) { 22 | 23 | context.translateBy(x: -point.x, y: -point.y) 24 | self.layer.render(in: context) 25 | 26 | let r = CGFloat(pixels[0])/CGFloat(255) 27 | let g = CGFloat(pixels[1])/CGFloat(255) 28 | let b = CGFloat(pixels[2])/CGFloat(255) 29 | let a = CGFloat(pixels[3])/CGFloat(255) 30 | 31 | let color = UIColor(red: r, green: g, blue: b, alpha: a) 32 | var nBrush: Brush = self._currentBrush 33 | if self.eyedropperOptions == .stroke { 34 | nBrush.strokeColor = color 35 | } else { 36 | nBrush.fillColor = color 37 | } 38 | self._currentBrush = nBrush 39 | self.delegate?.didSampleColor(on: self, sampledColor: color) 40 | } 41 | } 42 | 43 | 44 | 45 | } 46 | -------------------------------------------------------------------------------- /Canvas/Classes/Canvas+Layers.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Canvas+Layers.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 10/7/18. 6 | // 7 | 8 | import Foundation 9 | 10 | public extension Canvas { 11 | 12 | /************************ 13 | * * 14 | * VARIABLES * 15 | * * 16 | ************************/ 17 | 18 | 19 | 20 | 21 | 22 | /************************ 23 | * * 24 | * INIT * 25 | * * 26 | ************************/ 27 | 28 | 29 | 30 | 31 | 32 | /************************ 33 | * * 34 | * FUNCTIONS * 35 | * * 36 | ************************/ 37 | 38 | /** Adds a new layer to the canvas. */ 39 | public func addLayer(newLayer nl: CanvasLayer, position: LayerPosition) { 40 | if self._canvasLayers.count == 0 { 41 | self._canvasLayers = [nl] 42 | return 43 | } 44 | 45 | switch position { 46 | case .above: 47 | let insertIndex = self._currentCanvasLayer == 0 ? 0 : self._currentCanvasLayer 48 | self._canvasLayers.insert(nl, at: insertIndex) 49 | break 50 | case .below: 51 | self._canvasLayers.insert(nl, at: self._currentCanvasLayer+1) 52 | break 53 | } 54 | } 55 | 56 | 57 | /** Removes a layer from the canvas. */ 58 | public func removeLayer(at index: Int) { 59 | if self._canvasLayers.count == 0 { return } 60 | if index < 0 || index >= self._canvasLayers.count { return } 61 | 62 | self._canvasLayers.remove(at: index) 63 | 64 | if _currentCanvasLayer >= self._canvasLayers.count { 65 | self._currentCanvasLayer = self._canvasLayers.count - 1 66 | } 67 | 68 | setNeedsDisplay() 69 | } 70 | 71 | 72 | /** Switches the drawing to the specified layer. If an invalid layer index is put in, nothing will happen. */ 73 | public func switchLayer(to: Int) { 74 | if to >= _canvasLayers.count { _currentCanvasLayer = _canvasLayers.count - 1 } 75 | else if to < 0 { _currentCanvasLayer = 0 } 76 | else { _currentCanvasLayer = to } 77 | } 78 | 79 | 80 | /** Moves one layer to a new location. */ 81 | public func moveLayer(at: Int, toPosition to: Int) { 82 | if _canvasLayers.count == 0 { return } 83 | if at >= _canvasLayers.count { return } 84 | 85 | var t = to 86 | if to >= _canvasLayers.count { t = _canvasLayers.count - 1 } 87 | 88 | let layer = _canvasLayers[at] 89 | _canvasLayers.remove(at: at) 90 | _canvasLayers.insert(layer, at: t) 91 | 92 | let before = _currentCanvasLayer 93 | _currentCanvasLayer = at 94 | setNeedsDisplay() 95 | _currentCanvasLayer = before 96 | } 97 | 98 | 99 | /** Swaps the positions of two layers using the indexes of those layers. */ 100 | public func swapLayers(first: Int, second: Int) { 101 | if _canvasLayers.count == 0 { return } 102 | if first >= _canvasLayers.count { return } 103 | if second >= _canvasLayers.count { return } 104 | 105 | _canvasLayers.swapAt(first, second) 106 | 107 | let before = _currentCanvasLayer 108 | _currentCanvasLayer = second 109 | setNeedsDisplay() 110 | _currentCanvasLayer = before 111 | } 112 | 113 | 114 | /** Hides the layer at the given index. */ 115 | public func hideLayer(at: Int) { 116 | if at >= _canvasLayers.count { return } 117 | if at < 0 { return } 118 | 119 | _canvasLayers[at].isVisible = false 120 | 121 | setNeedsDisplay() 122 | } 123 | 124 | 125 | /** Makes the layer at the given index visible. */ 126 | public func showLayer(at: Int) { 127 | if at >= _canvasLayers.count { return } 128 | if at < 0 { return } 129 | 130 | _canvasLayers[at].isVisible = true 131 | 132 | setNeedsDisplay() 133 | } 134 | 135 | 136 | /** Locks a layer so that the user cannot draw on it. */ 137 | public func lockLayer(at: Int) { 138 | if _canvasLayers.count == 0 { return } 139 | if at >= _canvasLayers.count { return } 140 | 141 | _canvasLayers[at].allowsDrawing = false 142 | } 143 | 144 | 145 | /** Unlocks a layer so that the user can draw on it. */ 146 | public func unlockLayer(at: Int) { 147 | if _canvasLayers.count == 0 { return } 148 | if at >= _canvasLayers.count { return } 149 | 150 | _canvasLayers[at].allowsDrawing = true 151 | } 152 | 153 | 154 | 155 | 156 | /************************ 157 | * * 158 | * LAYOUT * 159 | * * 160 | ************************/ 161 | 162 | 163 | } 164 | -------------------------------------------------------------------------------- /Canvas/Classes/Canvas+Other.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Canvas+Other.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 10/7/18. 6 | // 7 | 8 | import Foundation 9 | 10 | extension Canvas { 11 | 12 | /************************ 13 | * * 14 | * VARIABLES * 15 | * * 16 | ************************/ 17 | 18 | 19 | 20 | 21 | 22 | 23 | /************************ 24 | * * 25 | * INIT * 26 | * * 27 | ************************/ 28 | 29 | 30 | 31 | 32 | 33 | /************************ 34 | * * 35 | * FUNCTIONS * 36 | * * 37 | ************************/ 38 | 39 | func handleSelection(with selectionArea: CGRect) { 40 | if self._currentCanvasLayer >= self._canvasLayers.count { return } 41 | let currLayer = self._canvasLayers[self._currentCanvasLayer] 42 | if currLayer.allowsDrawing == false { return } 43 | currLayer.selectedNodes.removeAll() 44 | 45 | // Find the nodes that are within the selection box. 46 | for node in currLayer.drawings { 47 | let path = build(from: node.points, using: node.instructions, tool: node.type) 48 | 49 | if selectionArea.contains(path.boundingBox) { 50 | currLayer.selectedNodes.append(node) 51 | } 52 | } 53 | 54 | // Delegate. 55 | self.delegate?.didSelectNodes(on: self, on: currLayer, selectedNodes: currLayer.selectedNodes) 56 | } 57 | 58 | 59 | 60 | 61 | 62 | 63 | /************************ 64 | * * 65 | * LAYOUT * 66 | * * 67 | ************************/ 68 | 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Canvas/Classes/Canvas+Paths.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Canvas+Paths.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 10/8/18. 6 | // 7 | 8 | import Foundation 9 | 10 | /** Builds and returns a CGMutablePath from a set of points and instructions. */ 11 | public func build(from points: [[CGPoint]], using instructions: [CGPathElementType], tool: CanvasTool) -> CGMutablePath { 12 | let mutablePath = CGMutablePath() 13 | if points.count == 0 { return mutablePath } 14 | if points[0].count == 0 { return mutablePath } 15 | 16 | mutablePath.move(to: points[0][0]) 17 | 18 | // Handle rectangles and ellipses. 19 | if tool == .rectangle || tool == .ellipse || tool == .selection { 20 | let first = points[0][0] 21 | let last = points[0][1] 22 | let w = last.x - first.x 23 | let h = last.y - first.y 24 | let dest = CGRect(x: first.x, y: first.y, width: w, height: h) 25 | 26 | if tool == .rectangle || tool == .selection { 27 | mutablePath.addRect(dest) 28 | } else if tool == .ellipse { 29 | mutablePath.addEllipse(in: dest) 30 | } 31 | return mutablePath 32 | } 33 | 34 | for i in 0..= self._canvasLayers.count { return } 20 | let currLayer = self._canvasLayers[self._currentCanvasLayer] 21 | 22 | if let next = nextNode { 23 | currLayer.drawings.append(next) 24 | 25 | // Undo/Redo. 26 | undoRedoManager.add(undo: { 27 | if currLayer.drawings.count > 0 { 28 | currLayer.drawings.removeLast() 29 | } 30 | return nil 31 | }, redo: { 32 | currLayer.drawings.append(next) 33 | }) 34 | undoRedoManager.clearRedos() 35 | } else { 36 | 37 | // Some tools do not produce nodes, so handle their actions differently here. 38 | switch _currentTool { 39 | case .eyedropper: 40 | handleEyedrop(point: currentPoint) 41 | break 42 | case .paint: 43 | var painted: [Node] = [] 44 | for node in currLayer.drawings { 45 | // Base case: the line tool. 46 | if node.type == .line { 47 | let lastColor = node.brush.strokeColor 48 | node.brush.strokeColor = self._currentBrush.strokeColor 49 | painted.append(node) 50 | 51 | // Undo/Redo. 52 | undoRedoManager.add(undo: { 53 | node.brush.strokeColor = lastColor 54 | }, redo: { 55 | let newColor = self._currentBrush.strokeColor 56 | node.brush.strokeColor = newColor 57 | return nil 58 | }) 59 | undoRedoManager.clearRedos() 60 | continue 61 | } 62 | 63 | let path = build(from: node.points, using: node.instructions, tool: node.type) 64 | 65 | // Only take the nodes where the touch is within the bounding box. 66 | if path.boundingBox.contains(currentPoint) { 67 | // Get the average points. 68 | let points = node.points.map { (p) -> CGPoint in 69 | var sumX: CGFloat = 0 70 | var sumY: CGFloat = 0 71 | for pt in p { 72 | sumX += pt.x 73 | sumY += pt.y 74 | } 75 | return CGPoint(x: sumX / CGFloat(p.count), y: sumY / CGFloat(p.count)) 76 | } 77 | 78 | // If the touch is on a point on the line, then color that. Otherwise fill the inside. 79 | var exit: Bool = false 80 | for pt in points { 81 | if pt.inRange(of: currentPoint, by: 5.0) { 82 | let lastColor = node.brush.strokeColor 83 | node.brush.strokeColor = self._currentBrush.strokeColor 84 | 85 | // Undo/Redo. 86 | undoRedoManager.add(undo: { 87 | node.brush.strokeColor = lastColor 88 | }, redo: { 89 | let newColor = self._currentBrush.strokeColor 90 | node.brush.strokeColor = newColor 91 | return nil 92 | }) 93 | undoRedoManager.clearRedos() 94 | 95 | exit = true 96 | break 97 | } 98 | } 99 | if exit == true { 100 | painted.append(node) 101 | continue 102 | } 103 | let lastColor = node.brush.fillColor 104 | node.brush.fillColor = self._currentBrush.fillColor 105 | painted.append(node) 106 | 107 | // Undo/Redo. 108 | undoRedoManager.add(undo: { 109 | node.brush.fillColor = lastColor 110 | }, redo: { 111 | let newColor = self._currentBrush.fillColor 112 | node.brush.fillColor = newColor 113 | return nil 114 | }) 115 | undoRedoManager.clearRedos() 116 | } 117 | } 118 | 119 | self.delegate?.didPaintNodes(on: self, nodes: painted, strokeColor: self.currentBrush.strokeColor, fillColor: self.currentBrush.fillColor) 120 | break 121 | default: 122 | break 123 | } 124 | 125 | } 126 | nextNode = nil 127 | setNeedsDisplay() 128 | 129 | // Call delegate method. 130 | self.delegate?.didFinishDrawing(on: self) 131 | } 132 | 133 | 134 | 135 | 136 | 137 | 138 | /************************ 139 | * * 140 | * TOUCHES * 141 | * * 142 | ************************/ 143 | 144 | public override func touchesBegan(_ touches: Set, with event: UIEvent?) { 145 | if self._currentCanvasLayer >= self._canvasLayers.count { return } 146 | let currLayer = self._canvasLayers[self._currentCanvasLayer] 147 | guard let touch = touches.first else { return } 148 | guard let allTouches = event?.allTouches else { return } 149 | if allTouches.count > 1 { return } 150 | if currLayer.allowsDrawing == false { return } 151 | 152 | // 1.) Set up the touch points. 153 | currentPoint = touch.location(in: self) 154 | lastPoint = touch.location(in: self) 155 | lastLastPoint = touch.location(in: self) 156 | eraserStartPoint = touch.location(in: self) 157 | 158 | // 2.) Create a new node that will be placed on the canvas. 159 | if _currentTool != .eyedropper && _currentTool != .eraser && _currentTool != .paint { 160 | nextNode = Node(type: self._currentTool) 161 | nextNode?.brush = currentBrush 162 | nextNode?.points.append([currentPoint]) 163 | nextNode?.instructions.append(CGPathElementType.moveToPoint) 164 | } 165 | if _currentTool == .selection && currLayer.selectedNodes.count > 0 { 166 | var atLeastOne: Bool = false 167 | for node in currLayer.selectedNodes { 168 | let path = build(from: node.points, using: node.instructions, tool: node.type) 169 | if path.boundingBox.contains(currentPoint) { 170 | atLeastOne = true 171 | break 172 | } 173 | } 174 | if atLeastOne == false { 175 | currLayer.selectedNodes.removeAll() 176 | nextNode = nil 177 | setNeedsDisplay() 178 | } 179 | } 180 | 181 | // 3.) Call delegate method. 182 | self.delegate?.willBeginDrawing(on: self) 183 | } 184 | 185 | public override func touchesMoved(_ touches: Set, with event: UIEvent?) { 186 | if self._currentCanvasLayer >= self._canvasLayers.count { return } 187 | let currLayer = self._canvasLayers[self._currentCanvasLayer] 188 | guard let touch = touches.first else { return } 189 | guard let allTouches = event?.allTouches else { return } 190 | if allTouches.count > 1 { return } 191 | if currLayer.allowsDrawing == false { return } 192 | 193 | // 1.) Update the touch points. 194 | currentPoint = touch.location(in: self) 195 | lastLastPoint = lastPoint 196 | lastPoint = touch.previousLocation(in: self) 197 | 198 | // 1.5) Calculate the translation of the touch. 199 | touch.deltaX = currentPoint.x - lastPoint.x 200 | touch.deltaY = currentPoint.y - lastPoint.y 201 | 202 | // 2.) Depending on the tool, add points and instructions for drawing. 203 | switch _currentTool { 204 | case .pen: 205 | guard let next = nextNode else { return } 206 | next.points.append([currentPoint, lastPoint, lastLastPoint]) 207 | next.instructions.append(CGPathElementType.addQuadCurveToPoint) 208 | break 209 | case .eraser: 210 | // 1.) Find all of the nodes where the touch is within its bounding box. This 211 | // will cut the number of nodes to look through down to 1 in the best case or "n" in the worst case. 212 | // 2.) For every touched node, map its points into an average of its points. This should still be the same 213 | // size array as before. Then, as you loop through each point, store its averages in an array at index i. 214 | // 3.) Loop through each set of average points for each node. If you come across one that is within range of 215 | // the touch, save that index i and remove it from the original nodes points points array. 216 | // 4.) Then split that node into two nodes. The first one will contain all the points and instructions from 217 | // 0...i with the last instruction being changed to closeSubpath. The second node will be from i...end 218 | // and the first instruction will be changed to moveToPoint. 219 | 220 | // 1. 221 | var touchingNodes: [Node] = [] 222 | for node in currLayer.drawings { 223 | let path = build(from: node.points, using: node.instructions, tool: node.type) 224 | if path.boundingBox.contains(currentPoint) { 225 | touchingNodes.append(node) 226 | } 227 | } 228 | 229 | // 2. 230 | let averages: NSMutableDictionary = NSMutableDictionary() 231 | for i in 0.. CGPoint in 234 | if p.count == 3 { 235 | return CGPoint(x: (p[0].x + p[1].x + p[2].x)/3, y: (p[0].y + p[1].y + p[2].y)/3) 236 | } else if p.count == 2 { 237 | return CGPoint(x: (p[0].x + p[1].x)/2, y: (p[0].y + p[1].y)/2) 238 | } else if p.count == 1 { 239 | return CGPoint(x: p[0].x, y: p[0].y) 240 | } else { 241 | return CGPoint() 242 | } 243 | } 244 | averages.setValue(averaged, forKey: "\(i)") 245 | } 246 | 247 | // 3. 248 | for (key, val) in averages { 249 | let averagesForNode = val as? [CGPoint] ?? [] 250 | 251 | for i in 0..= touchingNodes[key as? Int ?? 0].points.count { continue } 256 | 257 | let savedP = touchingNodes[key as? Int ?? 0].points[i] 258 | let savedI = touchingNodes[key as? Int ?? 0].instructions[i] 259 | 260 | touchingNodes[key as? Int ?? 0].points.remove(at: i) 261 | touchingNodes[key as? Int ?? 0].instructions.remove(at: i) 262 | 263 | // Undo/Redo. 264 | undoRedoManager.add(undo: { 265 | touchingNodes[key as? Int ?? 0].points.insert(savedP, at: i) 266 | touchingNodes[key as? Int ?? 0].instructions.insert(savedI, at: i) 267 | return nil 268 | }, redo: { 269 | if touchingNodes[key as? Int ?? 0].points.count > i { 270 | touchingNodes[key as? Int ?? 0].points.remove(at: i) 271 | } 272 | if touchingNodes[key as? Int ?? 0].instructions.count > i { 273 | touchingNodes[key as? Int ?? 0].instructions.remove(at: i) 274 | } 275 | return nil 276 | }) 277 | undoRedoManager.clearRedos() 278 | } 279 | } 280 | } 281 | break 282 | case .line: 283 | guard let next = nextNode else { return } 284 | let tempFirst = next.points[0][0] 285 | next.points.removeAll() 286 | next.instructions.removeAll() 287 | 288 | next.points.append([tempFirst]) 289 | next.points.append([currentPoint]) 290 | 291 | next.instructions.append(CGPathElementType.moveToPoint) 292 | next.instructions.append(CGPathElementType.addLineToPoint) 293 | break 294 | case .rectangle, .ellipse: 295 | guard let next = nextNode else { return } 296 | let tempFirst = next.points[0][0] 297 | next.points.removeAll() 298 | next.instructions.removeAll() 299 | 300 | next.points.append([tempFirst, currentPoint]) 301 | next.instructions.append(CGPathElementType.addLineToPoint) 302 | break 303 | case .selection: 304 | if currLayer.selectedNodes.count == 0 { 305 | guard let next = nextNode else { return } 306 | let tempFirst = next.points[0][0] 307 | next.points.removeAll() 308 | next.instructions.removeAll() 309 | 310 | next.points.append([tempFirst, currentPoint]) 311 | next.instructions.append(CGPathElementType.addLineToPoint) 312 | } else { 313 | nextNode = nil 314 | 315 | var containsAtLeastOne: Bool = false 316 | for node in currLayer.selectedNodes { 317 | // See if the current point is within the node's bounding box. 318 | let path = build(from: node.points, using: node.instructions, tool: node.type) 319 | if path.boundingBox.contains(currentPoint) { 320 | containsAtLeastOne = true 321 | break 322 | } 323 | } 324 | 325 | // Make sure the touch is within at least one bounding box. 326 | if containsAtLeastOne == true { 327 | for node in currLayer.selectedNodes { 328 | // Move the points by the selection translation amount. 329 | let nPoints = node.points.map { (points: [CGPoint]) -> [CGPoint] in 330 | var nP = points 331 | for i in 0.., with event: UIEvent?) { 363 | if self._currentCanvasLayer >= self._canvasLayers.count { return } 364 | let currLayer = self._canvasLayers[self._currentCanvasLayer] 365 | guard let allTouches = event?.allTouches else { return } 366 | if allTouches.count > 1 { return } 367 | if currLayer.allowsDrawing == false { return } 368 | 369 | if _currentTool == .selection { 370 | if currLayer.selectedNodes.count == 0 { 371 | guard let next = nextNode else { return } 372 | let first = next.points[0][0] 373 | let last = next.points[0][1] 374 | let w = last.x - first.x 375 | let h = last.y - first.y 376 | let dest = CGRect(x: first.x, y: first.y, width: w, height: h) 377 | 378 | handleSelection(with: dest) 379 | setNeedsDisplay() 380 | } 381 | nextNode = nil 382 | } else { 383 | finishDrawing() 384 | } 385 | } 386 | 387 | public override func touchesCancelled(_ touches: Set, with event: UIEvent?) { 388 | if self._currentCanvasLayer >= self._canvasLayers.count { return } 389 | let currLayer = self._canvasLayers[self._currentCanvasLayer] 390 | guard let allTouches = event?.allTouches else { return } 391 | if allTouches.count > 1 { return } 392 | if currLayer.allowsDrawing == false { return } 393 | 394 | if _currentTool == .selection { 395 | if currLayer.selectedNodes.count == 0 { 396 | guard let next = nextNode else { return } 397 | let first = next.points[0][0] 398 | let last = next.points[0][1] 399 | let w = last.x - first.x 400 | let h = last.y - first.y 401 | let dest = CGRect(x: first.x, y: first.y, width: w, height: h) 402 | 403 | handleSelection(with: dest) 404 | setNeedsDisplay() 405 | } 406 | nextNode = nil 407 | } else { 408 | finishDrawing() 409 | } 410 | } 411 | 412 | } 413 | -------------------------------------------------------------------------------- /Canvas/Classes/Canvas.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Canvas.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 10/7/18. 6 | // 7 | 8 | import Foundation 9 | 10 | /** An area of the screen that allows drawing. */ 11 | public class Canvas: UIView { 12 | 13 | /************************ 14 | * * 15 | * VARIABLES * 16 | * * 17 | ************************/ 18 | 19 | // -- PRIVATE VARS 20 | 21 | /** The touch points. */ 22 | internal var currentPoint: CGPoint = CGPoint() 23 | internal var lastPoint: CGPoint = CGPoint() 24 | internal var lastLastPoint: CGPoint = CGPoint() 25 | internal var eraserStartPoint: CGPoint = CGPoint() 26 | 27 | /** The next node to be drawn on the canvas. */ 28 | internal var nextNode: Node? = nil 29 | 30 | /** A collection of the layers on this canvas. */ 31 | internal var _canvasLayers: [CanvasLayer] = [] 32 | internal var _currentCanvasLayer: Int = 0 33 | 34 | /** The current brush that is being used to style drawings. */ 35 | internal var _currentBrush: Brush = Brush.Default 36 | 37 | /** The current tool that is being used to draw. */ 38 | internal var _currentTool: CanvasTool = CanvasTool.pen 39 | 40 | /** The copied nodes. */ 41 | internal var _copiedNodes: [Node] = [] 42 | 43 | 44 | 45 | // -- PUBLIC VARS 46 | 47 | /** Events delegate. */ 48 | public var delegate: CanvasEvents? 49 | 50 | /** The brush that is currently being used to style drawings. */ 51 | public var currentBrush: Brush { 52 | set { _currentBrush = newValue } 53 | get { return _currentBrush } 54 | } 55 | 56 | /** The tool that is currently being used to draw on the canvas. */ 57 | public var currentTool: CanvasTool { 58 | set { _currentTool = newValue } 59 | get { return _currentTool } 60 | } 61 | 62 | /** The action to use for the eyedropper: set stroke or fill color. */ 63 | public var eyedropperOptions: EyedropperOptions = .stroke 64 | 65 | /** The undo redo manager. */ 66 | public var undoRedoManager: UndoRedoManager = UndoRedoManager() 67 | 68 | 69 | 70 | 71 | // -- COMPUTED PROPS 72 | 73 | /** The layer that you are currently on. */ 74 | public var currentCanvasLayer: Int { 75 | return self._currentCanvasLayer 76 | } 77 | 78 | /** The layer that you are currently on. */ 79 | public var currentLayer: CanvasLayer? { 80 | if self._currentCanvasLayer < 0 || self._currentCanvasLayer >= self._canvasLayers.count { 81 | return nil 82 | } else { 83 | return self._canvasLayers[self._currentCanvasLayer] 84 | } 85 | } 86 | 87 | /** The layers of the canvas. */ 88 | public var canvasLayers: [CanvasLayer] { 89 | return self._canvasLayers 90 | } 91 | 92 | 93 | 94 | 95 | /************************ 96 | * * 97 | * INIT * 98 | * * 99 | ************************/ 100 | 101 | public required init?(coder aDecoder: NSCoder) { 102 | super.init(coder: aDecoder) 103 | setup() 104 | } 105 | 106 | public override init(frame: CGRect) { 107 | super.init(frame: frame) 108 | setup() 109 | } 110 | 111 | public init(createDefaultLayer: Bool) { 112 | super.init(frame: CGRect.zero) 113 | setup(createDefaultLayer: createDefaultLayer) 114 | } 115 | 116 | private func setup(createDefaultLayer: Bool = false) { 117 | if createDefaultLayer == true { 118 | let defLay = CanvasLayer(type: LayerType.raster) 119 | self.addLayer(newLayer: defLay, position: .above) 120 | } 121 | backgroundColor = .clear 122 | } 123 | 124 | 125 | 126 | 127 | /************************ 128 | * * 129 | * FUNCTIONS * 130 | * * 131 | ************************/ 132 | 133 | // -- UNDO / REDO / CLEAR -- 134 | 135 | /** Allows the user to define custom behavior for undo and redo. For example, a custom function to undo changing the tool. */ 136 | public func addCustomUndoRedo(cUndo: @escaping () -> Any?, cRedo: @escaping () -> Any?) { 137 | undoRedoManager.add(undo: cUndo, redo: cRedo) 138 | } 139 | 140 | 141 | /** Undo the last action on the canvas. */ 142 | public func undo() { 143 | let _ = undoRedoManager.performUndo() 144 | setNeedsDisplay() 145 | self.delegate?.didUndo(on: self) 146 | } 147 | 148 | 149 | /** Redo the last action on the canvas. */ 150 | public func redo() { 151 | let _ = undoRedoManager.performRedo() 152 | setNeedsDisplay() 153 | self.delegate?.didRedo(on: self) 154 | } 155 | 156 | 157 | /** Clears the entire canvas. */ 158 | public func clear() { 159 | for i in 0..<_canvasLayers.count { clearLayer(at: i) } 160 | setNeedsDisplay() 161 | } 162 | 163 | 164 | /** Clears a drawing on the layer at the specified index. */ 165 | public func clearLayer(at: Int) { 166 | if at < 0 || at >= _canvasLayers.count { return } 167 | _canvasLayers[at].clear(from: self) 168 | undoRedoManager.clearRedos() 169 | setNeedsDisplay() 170 | } 171 | 172 | 173 | 174 | // -- IMPORT / EXPORT -- 175 | 176 | /** Exports the canvas drawing. */ 177 | public func export() -> UIImage { 178 | UIGraphicsBeginImageContext(self.frame.size) 179 | guard let ctx = UIGraphicsGetCurrentContext() else { return UIImage() } 180 | self.layer.render(in: ctx) 181 | 182 | let img = UIGraphicsGetImageFromCurrentImageContext() 183 | UIGraphicsEndImageContext() 184 | return img ?? UIImage() 185 | } 186 | 187 | 188 | /** Exports the drawing on a specific layer. */ 189 | public func exportLayer(at: Int) -> UIImage { 190 | if at < 0 || at >= _canvasLayers.count { return UIImage() } 191 | if _canvasLayers[at].drawings.isEmpty { return UIImage() } 192 | UIGraphicsBeginImageContext(self.frame.size) 193 | 194 | for node in _canvasLayers[at].drawings { 195 | let path = build(from: node.points, using: node.instructions, tool: node.type) 196 | let shapeLayer = CAShapeLayer() 197 | shapeLayer.bounds = path.boundingBox 198 | shapeLayer.path = path 199 | shapeLayer.strokeColor = node.brush.strokeColor.cgColor 200 | shapeLayer.fillRule = CAShapeLayerFillRule.evenOdd 201 | shapeLayer.fillMode = CAMediaTimingFillMode.both 202 | shapeLayer.fillColor = node.brush.fillColor?.cgColor ?? nil 203 | shapeLayer.opacity = Float(node.brush.opacity) 204 | shapeLayer.lineWidth = node.brush.thickness 205 | shapeLayer.miterLimit = node.brush.miter 206 | switch node.brush.shape { 207 | case .butt: 208 | shapeLayer.lineCap = CAShapeLayerLineCap.butt 209 | break 210 | case .round: 211 | shapeLayer.lineCap = CAShapeLayerLineCap.round 212 | break 213 | case .square: 214 | shapeLayer.lineCap = CAShapeLayerLineCap.square 215 | break 216 | } 217 | switch node.brush.joinStyle { 218 | case .bevel: 219 | shapeLayer.lineJoin = CAShapeLayerLineJoin.bevel 220 | break 221 | case .miter: 222 | shapeLayer.lineJoin = CAShapeLayerLineJoin.miter 223 | break 224 | case .round: 225 | shapeLayer.lineJoin = CAShapeLayerLineJoin.round 226 | break 227 | } 228 | 229 | var nPos = path.boundingBox.origin 230 | nPos.x += path.boundingBox.width / 2 231 | nPos.y += path.boundingBox.height / 2 232 | shapeLayer.position = nPos 233 | 234 | shapeLayer.render(in: UIGraphicsGetCurrentContext()!) 235 | } 236 | 237 | let img = UIGraphicsGetImageFromCurrentImageContext() 238 | UIGraphicsEndImageContext() 239 | return img ?? UIImage() 240 | } 241 | 242 | 243 | /** Exports the given nodes to a UIImage. */ 244 | public static func export(nodes: [Node], size: CGSize) -> UIImage { 245 | UIGraphicsBeginImageContext(size) 246 | 247 | for node in nodes { 248 | let path = build(from: node.points, using: node.instructions, tool: node.type) 249 | let shapeLayer = CAShapeLayer() 250 | shapeLayer.bounds = path.boundingBox 251 | shapeLayer.path = path 252 | shapeLayer.strokeColor = node.brush.strokeColor.cgColor 253 | shapeLayer.fillRule = CAShapeLayerFillRule.evenOdd 254 | shapeLayer.fillMode = CAMediaTimingFillMode.both 255 | shapeLayer.fillColor = node.brush.fillColor?.cgColor ?? nil 256 | shapeLayer.opacity = Float(node.brush.opacity) 257 | shapeLayer.lineWidth = node.brush.thickness 258 | shapeLayer.miterLimit = node.brush.miter 259 | switch node.brush.shape { 260 | case .butt: 261 | shapeLayer.lineCap = CAShapeLayerLineCap.butt 262 | break 263 | case .round: 264 | shapeLayer.lineCap = CAShapeLayerLineCap.round 265 | break 266 | case .square: 267 | shapeLayer.lineCap = CAShapeLayerLineCap.square 268 | break 269 | } 270 | switch node.brush.joinStyle { 271 | case .bevel: 272 | shapeLayer.lineJoin = CAShapeLayerLineJoin.bevel 273 | break 274 | case .miter: 275 | shapeLayer.lineJoin = CAShapeLayerLineJoin.miter 276 | break 277 | case .round: 278 | shapeLayer.lineJoin = CAShapeLayerLineJoin.round 279 | break 280 | } 281 | 282 | var nPos = path.boundingBox.origin 283 | nPos.x += path.boundingBox.width / 2 284 | nPos.y += path.boundingBox.height / 2 285 | shapeLayer.position = nPos 286 | 287 | shapeLayer.render(in: UIGraphicsGetCurrentContext()!) 288 | } 289 | 290 | let img = UIGraphicsGetImageFromCurrentImageContext() 291 | UIGraphicsEndImageContext() 292 | 293 | return img ?? UIImage() 294 | } 295 | 296 | 297 | 298 | // -- COPY / PASTE -- 299 | 300 | /** Copies a particular node so that it can be pasted later. */ 301 | public func copy(nodes: [Node]) { 302 | _copiedNodes = nodes 303 | self.delegate?.didCopyNodes(on: self, nodes: nodes) 304 | } 305 | 306 | 307 | /** Pastes the copied node on to the current layer. */ 308 | public func paste() { 309 | guard let cl = currentLayer else { return } 310 | cl.drawings.append(contentsOf: _copiedNodes) 311 | setNeedsDisplay() 312 | 313 | undoRedoManager.add(undo: { 314 | if cl.drawings.count > 0 { 315 | cl.drawings.removeLast() 316 | } 317 | return nil 318 | }, redo: { 319 | cl.drawings.append(contentsOf: self._copiedNodes) 320 | return nil 321 | }) 322 | 323 | self.delegate?.didPasteNodes(on: self, on: cl, nodes: _copiedNodes) 324 | } 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | /************************ 338 | * * 339 | * DRAWING * 340 | * * 341 | ************************/ 342 | 343 | public override func draw(_ rect: CGRect) { 344 | // 1.) Clear all sublayers. 345 | layer.sublayers = [] 346 | 347 | // 2.) Go through each layer and render it using either raster or vector graphics. 348 | for i in (0.. Node? { 99 | if at < 0 || at >= drawings.count { return nil } 100 | return drawings[at] 101 | } 102 | 103 | 104 | /** Selects the given nodes on this layer. */ 105 | public func select(nodes: [Node], on canvas: Canvas) { 106 | self.selectedNodes = nodes 107 | canvas.setNeedsDisplay() 108 | } 109 | 110 | 111 | /** Returns the nodes that are selected. */ 112 | public func getSelectedNodes() -> [Node] { 113 | return self.selectedNodes 114 | } 115 | 116 | 117 | /** Removes the node at the given index from this layer. */ 118 | public func removeNode(at: Int) -> Node { 119 | let n = self.drawings.remove(at: at) 120 | return n 121 | } 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | /************************ 131 | * * 132 | * LAYOUT * 133 | * * 134 | ************************/ 135 | 136 | 137 | } 138 | -------------------------------------------------------------------------------- /Canvas/Classes/Enums.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Enums.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 10/7/18. 6 | // 7 | 8 | import Foundation 9 | 10 | /** Determines what type of canvas layer this is: one that uses raster graphics or svg. */ 11 | public enum LayerType: Int { 12 | /** A layer that uses pixel-based graphics. */ 13 | case raster = 0 14 | 15 | /** A layer that uses Scalable Vector Graphics. */ 16 | case vector = 1 17 | } 18 | 19 | 20 | /** The position of the layer relative to another. */ 21 | public enum LayerPosition: Int { 22 | case above = 0 23 | case below = 1 24 | } 25 | 26 | 27 | /** The type of tool to use when drawing on the canvas. */ 28 | public enum CanvasTool: Int { 29 | case pen = 0 30 | case eraser = 1 31 | case line = 2 32 | case rectangle = 3 33 | case ellipse = 4 34 | case paint = 5 35 | case eyedropper = 6 36 | case selection = 7 37 | } 38 | 39 | 40 | /** Relative position of points. */ 41 | public enum RelativePointPosition: Int { 42 | case upperRight = 0 43 | case upperLeft = 1 44 | case lowerRight = 2 45 | case lowerLeft = 3 46 | } 47 | 48 | 49 | /** Defines how the eyedropper tool should pick up colors: either by setting the stroke color or the fill color. */ 50 | public enum EyedropperOptions { 51 | case stroke 52 | case fill 53 | } 54 | 55 | 56 | /** Coding keys for brush. */ 57 | public enum BrushCodingKeys: CodingKey { 58 | case strokeColor 59 | case fillColor 60 | case thickness 61 | case opacity 62 | case miter 63 | case shape 64 | case join 65 | } 66 | 67 | /** Coding keys for node. */ 68 | public enum NodeCodingKeys: CodingKey { 69 | case type 70 | case points 71 | case instructions 72 | case brush 73 | } 74 | -------------------------------------------------------------------------------- /Canvas/Classes/Helpers.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Helpers.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 11/1/18. 6 | // 7 | 8 | import Foundation 9 | 10 | 11 | infix operator ** 12 | func **(lhs: CGFloat, rhs: CGFloat) -> CGFloat { 13 | return pow(lhs, rhs) 14 | } 15 | func **(lhs: Int, rhs: Int) -> Int { 16 | return Int(pow(CGFloat(lhs), CGFloat(rhs))) 17 | } 18 | -------------------------------------------------------------------------------- /Canvas/Classes/Node.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Node.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 10/7/18. 6 | // 7 | 8 | import Foundation 9 | 10 | /** A point, line, shape, etc. that exists on a layer of the canvas. */ 11 | public class Node: Codable { 12 | 13 | /************************ 14 | * * 15 | * VARIABLES * 16 | * * 17 | ************************/ 18 | 19 | // -- PRIVATE VARS 20 | 21 | /** What type of node this is. */ 22 | internal var type: CanvasTool! 23 | 24 | 25 | // -- PUBLIC VARS 26 | 27 | /** The points that make up this node. */ 28 | public var points: [[CGPoint]] = [] 29 | 30 | /** The instructions used to draw the points. */ 31 | public var instructions: [CGPathElementType] = [] 32 | 33 | /** The brush that this node uses for styling. */ 34 | public var brush: Brush = .Default 35 | 36 | 37 | // -- COMPUTED PROPERTIES 38 | 39 | 40 | 41 | 42 | /************************ 43 | * * 44 | * INIT * 45 | * * 46 | ************************/ 47 | 48 | public required init(from decoder: Decoder) throws { 49 | let container = try? decoder.container(keyedBy: NodeCodingKeys.self) 50 | let _type = try container?.decodeIfPresent(Int.self, forKey: NodeCodingKeys.type) ?? 0 51 | let _instructions = try container?.decodeIfPresent([Int32].self, forKey: NodeCodingKeys.instructions) 52 | 53 | type = CanvasTool(rawValue: _type) ?? .pen 54 | points = try container?.decodeIfPresent([[CGPoint]].self, forKey: NodeCodingKeys.points) ?? [] 55 | instructions = _instructions?.map({ (rv) -> CGPathElementType in return CGPathElementType(rawValue: rv) ?? .moveToPoint }) ?? [] 56 | brush = try container?.decodeIfPresent(Brush.self, forKey: NodeCodingKeys.brush) ?? .Default 57 | } 58 | 59 | public init(type: CanvasTool) { 60 | self.type = type 61 | } 62 | 63 | 64 | 65 | 66 | /************************ 67 | * * 68 | * FUNCTIONS * 69 | * * 70 | ************************/ 71 | 72 | 73 | 74 | 75 | /************************ 76 | * * 77 | * LAYOUT * 78 | * * 79 | ************************/ 80 | 81 | public func encode(to encoder: Encoder) throws { 82 | var container = encoder.container(keyedBy: NodeCodingKeys.self) 83 | try container.encode(type.rawValue, forKey: NodeCodingKeys.type) 84 | try container.encode(points, forKey: NodeCodingKeys.points) 85 | try container.encode(instructions.map { return $0.rawValue }, forKey: NodeCodingKeys.instructions) 86 | try container.encode(brush, forKey: NodeCodingKeys.brush) 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /Canvas/Classes/UIColor+RGB.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+RGG.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 11/1/18. 6 | // 7 | 8 | import Foundation 9 | 10 | 11 | func addColor(_ color1: UIColor, with color2: UIColor) -> UIColor { 12 | var (r1, g1, b1, a1) = (CGFloat(0), CGFloat(0), CGFloat(0), CGFloat(0)) 13 | var (r2, g2, b2, a2) = (CGFloat(0), CGFloat(0), CGFloat(0), CGFloat(0)) 14 | 15 | color1.getRed(&r1, green: &g1, blue: &b1, alpha: &a1) 16 | color2.getRed(&r2, green: &g2, blue: &b2, alpha: &a2) 17 | 18 | // add the components, but don't let them go above 1.0 19 | return UIColor(red: min(r1 + r2, 1), green: min(g1 + g2, 1), blue: min(b1 + b2, 1), alpha: (a1 + a2) / 2) 20 | } 21 | 22 | func multiplyColor(_ color: UIColor, by multiplier: CGFloat) -> UIColor { 23 | var (r, g, b, a) = (CGFloat(0), CGFloat(0), CGFloat(0), CGFloat(0)) 24 | color.getRed(&r, green: &g, blue: &b, alpha: &a) 25 | return UIColor(red: r * multiplier, green: g * multiplier, blue: b * multiplier, alpha: a) 26 | } 27 | 28 | public extension UIColor { 29 | 30 | /** Returns the RGBA values of a color, or (0,0,0,0) if the color could not be extracted. */ 31 | public var rgba: [CGFloat] { 32 | guard let comps = cgColor.components else { return [0, 0, 0, 0] } 33 | 34 | switch comps.count { 35 | case 0: return [1, 1, 1, 1] 36 | case 1: return [comps[0], 1, 1, 1] 37 | case 2: return [comps[0], comps[1], 1, 1] 38 | case 3: return [comps[0], comps[1], comps[2], 1] 39 | case 4: return [comps[0], comps[1], comps[2], comps[3]] 40 | default: return [1,1,1, 1] 41 | } 42 | } 43 | 44 | static func +(color1: UIColor, color2: UIColor) -> UIColor { 45 | return addColor(color1, with: color2) 46 | } 47 | 48 | static func *(color: UIColor, multiplier: Double) -> UIColor { 49 | return multiplyColor(color, by: CGFloat(multiplier)) 50 | } 51 | 52 | } 53 | 54 | public extension CGColor { 55 | 56 | /** Returns the RGBA values of a color, or (0,0,0,0) if the color could not be extracted. */ 57 | public var rgba: [CGFloat] { 58 | guard let comps = components else { return [0, 0, 0, 0] } 59 | 60 | switch comps.count { 61 | case 0: return [1, 1, 1, 1] 62 | case 1: return [comps[0], 1, 1, 1] 63 | case 2: return [comps[0], comps[1], 1, 1] 64 | case 3: return [comps[0], comps[1], comps[2], 1] 65 | case 4: return [comps[0], comps[1], comps[2], comps[3]] 66 | default: return [1,1,1, 1] 67 | } 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Canvas/Classes/UIImage+Properties.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIImage+Properties.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 11/3/18. 6 | // 7 | 8 | import Foundation 9 | 10 | /** Extension to UIImage that allows the adding of multiple images. */ 11 | public extension UIImage { 12 | 13 | public static func +(lhs: UIImage, rhs: UIImage) -> UIImage { 14 | let nWidth = max(lhs.size.width, rhs.size.width) 15 | let nHeight = max(lhs.size.height, rhs.size.height) 16 | let nSize = CGSize(width: nWidth, height: nHeight) 17 | 18 | UIGraphicsBeginImageContext(nSize) 19 | 20 | let lhsX = round((nSize.width - lhs.size.width) / 2) 21 | let lhsY = round((nSize.height - lhs.size.height) / 2) 22 | 23 | let rhsX = round((nSize.width - rhs.size.width) / 2) 24 | let rhsY = round((nSize.height - rhs.size.height) / 2) 25 | 26 | lhs.draw(at: CGPoint(x: lhsX, y: lhsY)) 27 | rhs.draw(at: CGPoint(x: rhsX, y: rhsY)) 28 | 29 | let combine: UIImage = UIGraphicsGetImageFromCurrentImageContext() ?? UIImage() 30 | UIGraphicsEndImageContext() 31 | 32 | return combine 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Canvas/Classes/UITouch+Translation.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UITouch+Translation.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 11/4/18. 6 | // 7 | 8 | import Foundation 9 | 10 | extension UITouch { 11 | private struct AssociatedKeys { 12 | static var dX: Int = 0 13 | static var dY: Int = 0 14 | } 15 | 16 | /** The amount that the touch has changed in the x direction from the moment it was last on the screen. */ 17 | var deltaX: CGFloat { 18 | get { return objc_getAssociatedObject(self, &AssociatedKeys.dX) as? CGFloat ?? 0 } 19 | set { objc_setAssociatedObject(self, &AssociatedKeys.dX, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) } 20 | } 21 | 22 | /** The amount that the touch has changed in the y direction from the moment it was last on the screen. */ 23 | var deltaY: CGFloat { 24 | get { return objc_getAssociatedObject(self, &AssociatedKeys.dY) as? CGFloat ?? 0 } 25 | set { objc_setAssociatedObject(self, &AssociatedKeys.dY, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) } 26 | } 27 | 28 | /** The amount that the touch has changed from the moment it was last on the screen. */ 29 | var translation: CGFloat { 30 | return CGFloat(sqrt((deltaX ** 2) + (deltaY ** 2))) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Canvas/Classes/UndoRedoManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UndoRedoManager.swift 3 | // Canvas 4 | // 5 | // Created by Adeola Uthman on 11/3/18. 6 | // 7 | 8 | import Foundation 9 | 10 | /** The manager that handles undoing and redoing actions while working with the canvas. The generic used here represents what should count toward the undo/redo stack. This way, users can define exactly what actions in their app should trigger undos and redos. */ 11 | public class UndoRedoManager { 12 | 13 | /************************ 14 | * * 15 | * VARIABLES * 16 | * * 17 | ************************/ 18 | 19 | /** The undo redo stack, which is an array of dictionaries of the format [undo/redo : function] */ 20 | var stack: [[Int : () -> Any?]] 21 | 22 | /** The separate redo stack to keep track of what can and should be redone next. */ 23 | var redos: [[Int : () -> Any?]] 24 | 25 | 26 | 27 | 28 | 29 | /************************ 30 | * * 31 | * INIT * 32 | * * 33 | ************************/ 34 | 35 | init() { 36 | stack = [] 37 | redos = [] 38 | } 39 | 40 | 41 | 42 | 43 | 44 | /************************ 45 | * * 46 | * FUNCTIONS * 47 | * * 48 | ************************/ 49 | 50 | /** Adds a new action to undos. */ 51 | public func add(undo: @escaping () -> Any?, redo: @escaping () -> Any?) { 52 | // Add two entries to the dictionary, an undo and a redo with the respective indexes. 53 | stack.append([0: undo, 1: redo]) 54 | } 55 | 56 | /** Undo the last event. */ 57 | public func performUndo() -> Any? { 58 | if stack.isEmpty == true { return nil } 59 | 60 | // Get the last item in the stack. 61 | guard let last = stack.popLast() else { return nil } 62 | 63 | // That last item is a function that says how something should be undone. Run the function. 64 | let val = last[0]?() 65 | 66 | // Now take the redo of that function and add it to the redo stack. 67 | redos.insert(last, at: 0) 68 | 69 | return val 70 | } 71 | 72 | /** Redo the last event. */ 73 | public func performRedo() -> Any? { 74 | if redos.isEmpty == true { return nil } 75 | 76 | // Get the last item in the redos. 77 | let last = redos.removeFirst() 78 | 79 | // Run that function to perform the redo. 80 | let val = last[1]?() 81 | 82 | // Make sure you add back the redo to the undo stack. 83 | stack.append(last) 84 | 85 | return val 86 | } 87 | 88 | /** Clears the redos. */ 89 | public func clearRedos() { 90 | redos.removeAll() 91 | } 92 | 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /CanvasLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Authman2/Canvas/642de2c90ac457132185039db2552bd47af38791/CanvasLogo.png -------------------------------------------------------------------------------- /Example/Canvas.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; }; 11 | 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; }; 12 | 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 607FACD91AFB9204008FA782 /* Main.storyboard */; }; 13 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; }; 14 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; }; 15 | 607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; }; 16 | CEF4F9329ABDE4A316CD9151 /* Pods_Canvas_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2AFFA8D84BA061CDFD9DBB89 /* Pods_Canvas_Tests.framework */; }; 17 | D21EAA9C309DCBC7E4FFB8B3 /* Pods_Canvas_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 57E4FE1601C262B5CFA5AEBE /* Pods_Canvas_Example.framework */; }; 18 | /* End PBXBuildFile section */ 19 | 20 | /* Begin PBXContainerItemProxy section */ 21 | 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */ = { 22 | isa = PBXContainerItemProxy; 23 | containerPortal = 607FACC81AFB9204008FA782 /* Project object */; 24 | proxyType = 1; 25 | remoteGlobalIDString = 607FACCF1AFB9204008FA782; 26 | remoteInfo = Canvas; 27 | }; 28 | /* End PBXContainerItemProxy section */ 29 | 30 | /* Begin PBXFileReference section */ 31 | 0468707EC9AA0FA18CBF86FC /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = ""; }; 32 | 2AFFA8D84BA061CDFD9DBB89 /* Pods_Canvas_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Canvas_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 3853A30EB0BD2050FAF4BBC2 /* Pods-Canvas_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Canvas_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example.debug.xcconfig"; sourceTree = ""; }; 34 | 39AFC965A33D234AA8DCA533 /* Pods-Canvas_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Canvas_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests.debug.xcconfig"; sourceTree = ""; }; 35 | 57E4FE1601C262B5CFA5AEBE /* Pods_Canvas_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Canvas_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | 607FACD01AFB9204008FA782 /* Canvas_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Canvas_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 37 | 607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 38 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 39 | 607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 40 | 607FACDA1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | 607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 42 | 607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 43 | 607FACE51AFB9204008FA782 /* Canvas_Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Canvas_Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | 607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 45 | 607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = ""; }; 46 | 75681211DE79395831C1D129 /* Canvas+.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = "Canvas+.podspec"; path = "../Canvas+.podspec"; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 47 | 82B03ADE79E7CA47317302DF /* Pods-Canvas_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Canvas_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example.release.xcconfig"; sourceTree = ""; }; 48 | 98653BE190258154B9DFAFC5 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; }; 49 | C25C2F12BD9153FDAD565888 /* Pods-Canvas_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Canvas_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests.release.xcconfig"; sourceTree = ""; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 607FACCD1AFB9204008FA782 /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | D21EAA9C309DCBC7E4FFB8B3 /* Pods_Canvas_Example.framework in Frameworks */, 58 | ); 59 | runOnlyForDeploymentPostprocessing = 0; 60 | }; 61 | 607FACE21AFB9204008FA782 /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | CEF4F9329ABDE4A316CD9151 /* Pods_Canvas_Tests.framework in Frameworks */, 66 | ); 67 | runOnlyForDeploymentPostprocessing = 0; 68 | }; 69 | /* End PBXFrameworksBuildPhase section */ 70 | 71 | /* Begin PBXGroup section */ 72 | 45BF886431785BA9AEDF46A8 /* Frameworks */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 57E4FE1601C262B5CFA5AEBE /* Pods_Canvas_Example.framework */, 76 | 2AFFA8D84BA061CDFD9DBB89 /* Pods_Canvas_Tests.framework */, 77 | ); 78 | name = Frameworks; 79 | sourceTree = ""; 80 | }; 81 | 607FACC71AFB9204008FA782 = { 82 | isa = PBXGroup; 83 | children = ( 84 | 607FACF51AFB993E008FA782 /* Podspec Metadata */, 85 | 607FACD21AFB9204008FA782 /* Example for Canvas */, 86 | 607FACE81AFB9204008FA782 /* Tests */, 87 | 607FACD11AFB9204008FA782 /* Products */, 88 | 7023DA6ED6DBB6DF834D49E7 /* Pods */, 89 | 45BF886431785BA9AEDF46A8 /* Frameworks */, 90 | ); 91 | sourceTree = ""; 92 | }; 93 | 607FACD11AFB9204008FA782 /* Products */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 607FACD01AFB9204008FA782 /* Canvas_Example.app */, 97 | 607FACE51AFB9204008FA782 /* Canvas_Tests.xctest */, 98 | ); 99 | name = Products; 100 | sourceTree = ""; 101 | }; 102 | 607FACD21AFB9204008FA782 /* Example for Canvas */ = { 103 | isa = PBXGroup; 104 | children = ( 105 | 607FACD51AFB9204008FA782 /* AppDelegate.swift */, 106 | 607FACD71AFB9204008FA782 /* ViewController.swift */, 107 | 607FACD91AFB9204008FA782 /* Main.storyboard */, 108 | 607FACDC1AFB9204008FA782 /* Images.xcassets */, 109 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */, 110 | 607FACD31AFB9204008FA782 /* Supporting Files */, 111 | ); 112 | name = "Example for Canvas"; 113 | path = Canvas; 114 | sourceTree = ""; 115 | }; 116 | 607FACD31AFB9204008FA782 /* Supporting Files */ = { 117 | isa = PBXGroup; 118 | children = ( 119 | 607FACD41AFB9204008FA782 /* Info.plist */, 120 | ); 121 | name = "Supporting Files"; 122 | sourceTree = ""; 123 | }; 124 | 607FACE81AFB9204008FA782 /* Tests */ = { 125 | isa = PBXGroup; 126 | children = ( 127 | 607FACEB1AFB9204008FA782 /* Tests.swift */, 128 | 607FACE91AFB9204008FA782 /* Supporting Files */, 129 | ); 130 | path = Tests; 131 | sourceTree = ""; 132 | }; 133 | 607FACE91AFB9204008FA782 /* Supporting Files */ = { 134 | isa = PBXGroup; 135 | children = ( 136 | 607FACEA1AFB9204008FA782 /* Info.plist */, 137 | ); 138 | name = "Supporting Files"; 139 | sourceTree = ""; 140 | }; 141 | 607FACF51AFB993E008FA782 /* Podspec Metadata */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | 75681211DE79395831C1D129 /* Canvas+.podspec */, 145 | 98653BE190258154B9DFAFC5 /* README.md */, 146 | 0468707EC9AA0FA18CBF86FC /* LICENSE */, 147 | ); 148 | name = "Podspec Metadata"; 149 | sourceTree = ""; 150 | }; 151 | 7023DA6ED6DBB6DF834D49E7 /* Pods */ = { 152 | isa = PBXGroup; 153 | children = ( 154 | 3853A30EB0BD2050FAF4BBC2 /* Pods-Canvas_Example.debug.xcconfig */, 155 | 82B03ADE79E7CA47317302DF /* Pods-Canvas_Example.release.xcconfig */, 156 | 39AFC965A33D234AA8DCA533 /* Pods-Canvas_Tests.debug.xcconfig */, 157 | C25C2F12BD9153FDAD565888 /* Pods-Canvas_Tests.release.xcconfig */, 158 | ); 159 | name = Pods; 160 | sourceTree = ""; 161 | }; 162 | /* End PBXGroup section */ 163 | 164 | /* Begin PBXNativeTarget section */ 165 | 607FACCF1AFB9204008FA782 /* Canvas_Example */ = { 166 | isa = PBXNativeTarget; 167 | buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "Canvas_Example" */; 168 | buildPhases = ( 169 | 8964F9AAF479552A0BE7623D /* [CP] Check Pods Manifest.lock */, 170 | 607FACCC1AFB9204008FA782 /* Sources */, 171 | 607FACCD1AFB9204008FA782 /* Frameworks */, 172 | 607FACCE1AFB9204008FA782 /* Resources */, 173 | C80D3DD9ADD25235423F5C7F /* [CP] Embed Pods Frameworks */, 174 | 9844214D84F5A2D91D554682 /* [CP] Copy Pods Resources */, 175 | ); 176 | buildRules = ( 177 | ); 178 | dependencies = ( 179 | ); 180 | name = Canvas_Example; 181 | productName = Canvas; 182 | productReference = 607FACD01AFB9204008FA782 /* Canvas_Example.app */; 183 | productType = "com.apple.product-type.application"; 184 | }; 185 | 607FACE41AFB9204008FA782 /* Canvas_Tests */ = { 186 | isa = PBXNativeTarget; 187 | buildConfigurationList = 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "Canvas_Tests" */; 188 | buildPhases = ( 189 | 90A282B58585576D4A522128 /* [CP] Check Pods Manifest.lock */, 190 | 607FACE11AFB9204008FA782 /* Sources */, 191 | 607FACE21AFB9204008FA782 /* Frameworks */, 192 | 607FACE31AFB9204008FA782 /* Resources */, 193 | F0971139A864C96B51D5E8A1 /* [CP] Embed Pods Frameworks */, 194 | B5AFD37A37145A8F27E23B32 /* [CP] Copy Pods Resources */, 195 | ); 196 | buildRules = ( 197 | ); 198 | dependencies = ( 199 | 607FACE71AFB9204008FA782 /* PBXTargetDependency */, 200 | ); 201 | name = Canvas_Tests; 202 | productName = Tests; 203 | productReference = 607FACE51AFB9204008FA782 /* Canvas_Tests.xctest */; 204 | productType = "com.apple.product-type.bundle.unit-test"; 205 | }; 206 | /* End PBXNativeTarget section */ 207 | 208 | /* Begin PBXProject section */ 209 | 607FACC81AFB9204008FA782 /* Project object */ = { 210 | isa = PBXProject; 211 | attributes = { 212 | LastSwiftUpdateCheck = 0830; 213 | LastUpgradeCheck = 0930; 214 | ORGANIZATIONNAME = CocoaPods; 215 | TargetAttributes = { 216 | 607FACCF1AFB9204008FA782 = { 217 | CreatedOnToolsVersion = 6.3.1; 218 | DevelopmentTeam = TJLM3363BG; 219 | LastSwiftMigration = 1000; 220 | ProvisioningStyle = Automatic; 221 | }; 222 | 607FACE41AFB9204008FA782 = { 223 | CreatedOnToolsVersion = 6.3.1; 224 | DevelopmentTeam = TJLM3363BG; 225 | LastSwiftMigration = 1000; 226 | TestTargetID = 607FACCF1AFB9204008FA782; 227 | }; 228 | }; 229 | }; 230 | buildConfigurationList = 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "Canvas" */; 231 | compatibilityVersion = "Xcode 3.2"; 232 | developmentRegion = English; 233 | hasScannedForEncodings = 0; 234 | knownRegions = ( 235 | en, 236 | Base, 237 | ); 238 | mainGroup = 607FACC71AFB9204008FA782; 239 | productRefGroup = 607FACD11AFB9204008FA782 /* Products */; 240 | projectDirPath = ""; 241 | projectRoot = ""; 242 | targets = ( 243 | 607FACCF1AFB9204008FA782 /* Canvas_Example */, 244 | 607FACE41AFB9204008FA782 /* Canvas_Tests */, 245 | ); 246 | }; 247 | /* End PBXProject section */ 248 | 249 | /* Begin PBXResourcesBuildPhase section */ 250 | 607FACCE1AFB9204008FA782 /* Resources */ = { 251 | isa = PBXResourcesBuildPhase; 252 | buildActionMask = 2147483647; 253 | files = ( 254 | 607FACDB1AFB9204008FA782 /* Main.storyboard in Resources */, 255 | 607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */, 256 | 607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */, 257 | ); 258 | runOnlyForDeploymentPostprocessing = 0; 259 | }; 260 | 607FACE31AFB9204008FA782 /* Resources */ = { 261 | isa = PBXResourcesBuildPhase; 262 | buildActionMask = 2147483647; 263 | files = ( 264 | ); 265 | runOnlyForDeploymentPostprocessing = 0; 266 | }; 267 | /* End PBXResourcesBuildPhase section */ 268 | 269 | /* Begin PBXShellScriptBuildPhase section */ 270 | 8964F9AAF479552A0BE7623D /* [CP] Check Pods Manifest.lock */ = { 271 | isa = PBXShellScriptBuildPhase; 272 | buildActionMask = 2147483647; 273 | files = ( 274 | ); 275 | inputPaths = ( 276 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 277 | "${PODS_ROOT}/Manifest.lock", 278 | ); 279 | name = "[CP] Check Pods Manifest.lock"; 280 | outputPaths = ( 281 | "$(DERIVED_FILE_DIR)/Pods-Canvas_Example-checkManifestLockResult.txt", 282 | ); 283 | runOnlyForDeploymentPostprocessing = 0; 284 | shellPath = /bin/sh; 285 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 286 | showEnvVarsInLog = 0; 287 | }; 288 | 90A282B58585576D4A522128 /* [CP] Check Pods Manifest.lock */ = { 289 | isa = PBXShellScriptBuildPhase; 290 | buildActionMask = 2147483647; 291 | files = ( 292 | ); 293 | inputPaths = ( 294 | "${PODS_PODFILE_DIR_PATH}/Podfile.lock", 295 | "${PODS_ROOT}/Manifest.lock", 296 | ); 297 | name = "[CP] Check Pods Manifest.lock"; 298 | outputPaths = ( 299 | "$(DERIVED_FILE_DIR)/Pods-Canvas_Tests-checkManifestLockResult.txt", 300 | ); 301 | runOnlyForDeploymentPostprocessing = 0; 302 | shellPath = /bin/sh; 303 | shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; 304 | showEnvVarsInLog = 0; 305 | }; 306 | 9844214D84F5A2D91D554682 /* [CP] Copy Pods Resources */ = { 307 | isa = PBXShellScriptBuildPhase; 308 | buildActionMask = 2147483647; 309 | files = ( 310 | ); 311 | inputPaths = ( 312 | ); 313 | name = "[CP] Copy Pods Resources"; 314 | outputPaths = ( 315 | ); 316 | runOnlyForDeploymentPostprocessing = 0; 317 | shellPath = /bin/sh; 318 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example-resources.sh\"\n"; 319 | showEnvVarsInLog = 0; 320 | }; 321 | B5AFD37A37145A8F27E23B32 /* [CP] Copy Pods Resources */ = { 322 | isa = PBXShellScriptBuildPhase; 323 | buildActionMask = 2147483647; 324 | files = ( 325 | ); 326 | inputPaths = ( 327 | ); 328 | name = "[CP] Copy Pods Resources"; 329 | outputPaths = ( 330 | ); 331 | runOnlyForDeploymentPostprocessing = 0; 332 | shellPath = /bin/sh; 333 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests-resources.sh\"\n"; 334 | showEnvVarsInLog = 0; 335 | }; 336 | C80D3DD9ADD25235423F5C7F /* [CP] Embed Pods Frameworks */ = { 337 | isa = PBXShellScriptBuildPhase; 338 | buildActionMask = 2147483647; 339 | files = ( 340 | ); 341 | inputPaths = ( 342 | "${SRCROOT}/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example-frameworks.sh", 343 | "${BUILT_PRODUCTS_DIR}/Canvas/Canvas.framework", 344 | ); 345 | name = "[CP] Embed Pods Frameworks"; 346 | outputPaths = ( 347 | "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Canvas.framework", 348 | ); 349 | runOnlyForDeploymentPostprocessing = 0; 350 | shellPath = /bin/sh; 351 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example-frameworks.sh\"\n"; 352 | showEnvVarsInLog = 0; 353 | }; 354 | F0971139A864C96B51D5E8A1 /* [CP] Embed Pods Frameworks */ = { 355 | isa = PBXShellScriptBuildPhase; 356 | buildActionMask = 2147483647; 357 | files = ( 358 | ); 359 | inputPaths = ( 360 | ); 361 | name = "[CP] Embed Pods Frameworks"; 362 | outputPaths = ( 363 | ); 364 | runOnlyForDeploymentPostprocessing = 0; 365 | shellPath = /bin/sh; 366 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests-frameworks.sh\"\n"; 367 | showEnvVarsInLog = 0; 368 | }; 369 | /* End PBXShellScriptBuildPhase section */ 370 | 371 | /* Begin PBXSourcesBuildPhase section */ 372 | 607FACCC1AFB9204008FA782 /* Sources */ = { 373 | isa = PBXSourcesBuildPhase; 374 | buildActionMask = 2147483647; 375 | files = ( 376 | 607FACD81AFB9204008FA782 /* ViewController.swift in Sources */, 377 | 607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */, 378 | ); 379 | runOnlyForDeploymentPostprocessing = 0; 380 | }; 381 | 607FACE11AFB9204008FA782 /* Sources */ = { 382 | isa = PBXSourcesBuildPhase; 383 | buildActionMask = 2147483647; 384 | files = ( 385 | 607FACEC1AFB9204008FA782 /* Tests.swift in Sources */, 386 | ); 387 | runOnlyForDeploymentPostprocessing = 0; 388 | }; 389 | /* End PBXSourcesBuildPhase section */ 390 | 391 | /* Begin PBXTargetDependency section */ 392 | 607FACE71AFB9204008FA782 /* PBXTargetDependency */ = { 393 | isa = PBXTargetDependency; 394 | target = 607FACCF1AFB9204008FA782 /* Canvas_Example */; 395 | targetProxy = 607FACE61AFB9204008FA782 /* PBXContainerItemProxy */; 396 | }; 397 | /* End PBXTargetDependency section */ 398 | 399 | /* Begin PBXVariantGroup section */ 400 | 607FACD91AFB9204008FA782 /* Main.storyboard */ = { 401 | isa = PBXVariantGroup; 402 | children = ( 403 | 607FACDA1AFB9204008FA782 /* Base */, 404 | ); 405 | name = Main.storyboard; 406 | sourceTree = ""; 407 | }; 408 | 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */ = { 409 | isa = PBXVariantGroup; 410 | children = ( 411 | 607FACDF1AFB9204008FA782 /* Base */, 412 | ); 413 | name = LaunchScreen.xib; 414 | sourceTree = ""; 415 | }; 416 | /* End PBXVariantGroup section */ 417 | 418 | /* Begin XCBuildConfiguration section */ 419 | 607FACED1AFB9204008FA782 /* Debug */ = { 420 | isa = XCBuildConfiguration; 421 | buildSettings = { 422 | ALWAYS_SEARCH_USER_PATHS = NO; 423 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 424 | CLANG_CXX_LIBRARY = "libc++"; 425 | CLANG_ENABLE_MODULES = YES; 426 | CLANG_ENABLE_OBJC_ARC = YES; 427 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 428 | CLANG_WARN_BOOL_CONVERSION = YES; 429 | CLANG_WARN_COMMA = YES; 430 | CLANG_WARN_CONSTANT_CONVERSION = YES; 431 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 432 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 433 | CLANG_WARN_EMPTY_BODY = YES; 434 | CLANG_WARN_ENUM_CONVERSION = YES; 435 | CLANG_WARN_INFINITE_RECURSION = YES; 436 | CLANG_WARN_INT_CONVERSION = YES; 437 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 438 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 439 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 440 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 441 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 442 | CLANG_WARN_STRICT_PROTOTYPES = YES; 443 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 444 | CLANG_WARN_UNREACHABLE_CODE = YES; 445 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 446 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 447 | COPY_PHASE_STRIP = NO; 448 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 449 | ENABLE_STRICT_OBJC_MSGSEND = YES; 450 | ENABLE_TESTABILITY = YES; 451 | GCC_C_LANGUAGE_STANDARD = gnu99; 452 | GCC_DYNAMIC_NO_PIC = NO; 453 | GCC_NO_COMMON_BLOCKS = YES; 454 | GCC_OPTIMIZATION_LEVEL = 0; 455 | GCC_PREPROCESSOR_DEFINITIONS = ( 456 | "DEBUG=1", 457 | "$(inherited)", 458 | ); 459 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 460 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 461 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 462 | GCC_WARN_UNDECLARED_SELECTOR = YES; 463 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 464 | GCC_WARN_UNUSED_FUNCTION = YES; 465 | GCC_WARN_UNUSED_VARIABLE = YES; 466 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 467 | MTL_ENABLE_DEBUG_INFO = YES; 468 | ONLY_ACTIVE_ARCH = YES; 469 | SDKROOT = iphoneos; 470 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 471 | }; 472 | name = Debug; 473 | }; 474 | 607FACEE1AFB9204008FA782 /* Release */ = { 475 | isa = XCBuildConfiguration; 476 | buildSettings = { 477 | ALWAYS_SEARCH_USER_PATHS = NO; 478 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 479 | CLANG_CXX_LIBRARY = "libc++"; 480 | CLANG_ENABLE_MODULES = YES; 481 | CLANG_ENABLE_OBJC_ARC = YES; 482 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 483 | CLANG_WARN_BOOL_CONVERSION = YES; 484 | CLANG_WARN_COMMA = YES; 485 | CLANG_WARN_CONSTANT_CONVERSION = YES; 486 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 487 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 488 | CLANG_WARN_EMPTY_BODY = YES; 489 | CLANG_WARN_ENUM_CONVERSION = YES; 490 | CLANG_WARN_INFINITE_RECURSION = YES; 491 | CLANG_WARN_INT_CONVERSION = YES; 492 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 493 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 494 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 495 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 496 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 497 | CLANG_WARN_STRICT_PROTOTYPES = YES; 498 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 499 | CLANG_WARN_UNREACHABLE_CODE = YES; 500 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 501 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 502 | COPY_PHASE_STRIP = NO; 503 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 504 | ENABLE_NS_ASSERTIONS = NO; 505 | ENABLE_STRICT_OBJC_MSGSEND = YES; 506 | GCC_C_LANGUAGE_STANDARD = gnu99; 507 | GCC_NO_COMMON_BLOCKS = YES; 508 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 509 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 510 | GCC_WARN_UNDECLARED_SELECTOR = YES; 511 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 512 | GCC_WARN_UNUSED_FUNCTION = YES; 513 | GCC_WARN_UNUSED_VARIABLE = YES; 514 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 515 | MTL_ENABLE_DEBUG_INFO = NO; 516 | SDKROOT = iphoneos; 517 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 518 | VALIDATE_PRODUCT = YES; 519 | }; 520 | name = Release; 521 | }; 522 | 607FACF01AFB9204008FA782 /* Debug */ = { 523 | isa = XCBuildConfiguration; 524 | baseConfigurationReference = 3853A30EB0BD2050FAF4BBC2 /* Pods-Canvas_Example.debug.xcconfig */; 525 | buildSettings = { 526 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 527 | CODE_SIGN_IDENTITY = "iPhone Developer"; 528 | CODE_SIGN_STYLE = Automatic; 529 | DEVELOPMENT_TEAM = TJLM3363BG; 530 | INFOPLIST_FILE = Canvas/Info.plist; 531 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 532 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 533 | MODULE_NAME = ExampleApp; 534 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 535 | PRODUCT_NAME = "$(TARGET_NAME)"; 536 | PROVISIONING_PROFILE_SPECIFIER = ""; 537 | SWIFT_VERSION = 4.2; 538 | TARGETED_DEVICE_FAMILY = "1,2"; 539 | }; 540 | name = Debug; 541 | }; 542 | 607FACF11AFB9204008FA782 /* Release */ = { 543 | isa = XCBuildConfiguration; 544 | baseConfigurationReference = 82B03ADE79E7CA47317302DF /* Pods-Canvas_Example.release.xcconfig */; 545 | buildSettings = { 546 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 547 | CODE_SIGN_IDENTITY = "iPhone Developer"; 548 | CODE_SIGN_STYLE = Automatic; 549 | DEVELOPMENT_TEAM = TJLM3363BG; 550 | INFOPLIST_FILE = Canvas/Info.plist; 551 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 552 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 553 | MODULE_NAME = ExampleApp; 554 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; 555 | PRODUCT_NAME = "$(TARGET_NAME)"; 556 | PROVISIONING_PROFILE_SPECIFIER = ""; 557 | SWIFT_VERSION = 4.2; 558 | TARGETED_DEVICE_FAMILY = "1,2"; 559 | }; 560 | name = Release; 561 | }; 562 | 607FACF31AFB9204008FA782 /* Debug */ = { 563 | isa = XCBuildConfiguration; 564 | baseConfigurationReference = 39AFC965A33D234AA8DCA533 /* Pods-Canvas_Tests.debug.xcconfig */; 565 | buildSettings = { 566 | DEVELOPMENT_TEAM = TJLM3363BG; 567 | FRAMEWORK_SEARCH_PATHS = ( 568 | "$(SDKROOT)/Developer/Library/Frameworks", 569 | "$(inherited)", 570 | ); 571 | GCC_PREPROCESSOR_DEFINITIONS = ( 572 | "DEBUG=1", 573 | "$(inherited)", 574 | ); 575 | INFOPLIST_FILE = Tests/Info.plist; 576 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 577 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; 578 | PRODUCT_NAME = "$(TARGET_NAME)"; 579 | SWIFT_VERSION = 4.2; 580 | }; 581 | name = Debug; 582 | }; 583 | 607FACF41AFB9204008FA782 /* Release */ = { 584 | isa = XCBuildConfiguration; 585 | baseConfigurationReference = C25C2F12BD9153FDAD565888 /* Pods-Canvas_Tests.release.xcconfig */; 586 | buildSettings = { 587 | DEVELOPMENT_TEAM = TJLM3363BG; 588 | FRAMEWORK_SEARCH_PATHS = ( 589 | "$(SDKROOT)/Developer/Library/Frameworks", 590 | "$(inherited)", 591 | ); 592 | INFOPLIST_FILE = Tests/Info.plist; 593 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 594 | PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)"; 595 | PRODUCT_NAME = "$(TARGET_NAME)"; 596 | SWIFT_VERSION = 4.2; 597 | }; 598 | name = Release; 599 | }; 600 | /* End XCBuildConfiguration section */ 601 | 602 | /* Begin XCConfigurationList section */ 603 | 607FACCB1AFB9204008FA782 /* Build configuration list for PBXProject "Canvas" */ = { 604 | isa = XCConfigurationList; 605 | buildConfigurations = ( 606 | 607FACED1AFB9204008FA782 /* Debug */, 607 | 607FACEE1AFB9204008FA782 /* Release */, 608 | ); 609 | defaultConfigurationIsVisible = 0; 610 | defaultConfigurationName = Release; 611 | }; 612 | 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "Canvas_Example" */ = { 613 | isa = XCConfigurationList; 614 | buildConfigurations = ( 615 | 607FACF01AFB9204008FA782 /* Debug */, 616 | 607FACF11AFB9204008FA782 /* Release */, 617 | ); 618 | defaultConfigurationIsVisible = 0; 619 | defaultConfigurationName = Release; 620 | }; 621 | 607FACF21AFB9204008FA782 /* Build configuration list for PBXNativeTarget "Canvas_Tests" */ = { 622 | isa = XCConfigurationList; 623 | buildConfigurations = ( 624 | 607FACF31AFB9204008FA782 /* Debug */, 625 | 607FACF41AFB9204008FA782 /* Release */, 626 | ); 627 | defaultConfigurationIsVisible = 0; 628 | defaultConfigurationName = Release; 629 | }; 630 | /* End XCConfigurationList section */ 631 | }; 632 | rootObject = 607FACC81AFB9204008FA782 /* Project object */; 633 | } 634 | -------------------------------------------------------------------------------- /Example/Canvas.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Canvas.xcodeproj/xcshareddata/xcschemes/Canvas-Example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 67 | 68 | 78 | 80 | 86 | 87 | 88 | 89 | 90 | 91 | 97 | 99 | 105 | 106 | 107 | 108 | 110 | 111 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /Example/Canvas.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Example/Canvas.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Canvas/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Canvas 4 | // 5 | // Created by authman2 on 01/12/2018. 6 | // Copyright (c) 2018 authman2. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | 19 | window = UIWindow(frame: UIScreen.main.bounds) 20 | window?.makeKeyAndVisible() 21 | window?.rootViewController = ViewController() 22 | 23 | return true 24 | } 25 | 26 | func applicationWillResignActive(_ application: UIApplication) { 27 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 28 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 29 | } 30 | 31 | func applicationDidEnterBackground(_ application: UIApplication) { 32 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 33 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 34 | } 35 | 36 | func applicationWillEnterForeground(_ application: UIApplication) { 37 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 38 | } 39 | 40 | func applicationDidBecomeActive(_ application: UIApplication) { 41 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 42 | } 43 | 44 | func applicationWillTerminate(_ application: UIApplication) { 45 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 46 | } 47 | 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /Example/Canvas/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 25 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Example/Canvas/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Example/Canvas/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "size" : "1024x1024", 46 | "scale" : "1x" 47 | } 48 | ], 49 | "info" : { 50 | "version" : 1, 51 | "author" : "xcode" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Example/Canvas/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NSPhotoLibraryAddUsageDescription 6 | This app needs to access your photos so it ca save images from the canvas. 7 | CFBundleDevelopmentRegion 8 | en 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Example/Canvas/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Canvas 4 | // 5 | // Created by authman2 on 01/12/2018. 6 | // Copyright (c) 2018 authman2. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import Canvas 11 | 12 | class ViewController: UIViewController, CanvasEvents, UINavigationControllerDelegate, UIImagePickerControllerDelegate { 13 | 14 | /************************ 15 | * * 16 | * VARIABLES * 17 | * * 18 | ************************/ 19 | 20 | /** The background holder for the canvas so that it can have a white background. */ 21 | lazy var canvasView: UIView = { 22 | let a = UIView() 23 | a.translatesAutoresizingMaskIntoConstraints = false 24 | a.backgroundColor = .brown 25 | 26 | return a 27 | }() 28 | 29 | 30 | /** The actual canvas, which has a clear background. */ 31 | lazy var canvas: Canvas = { 32 | let a = Canvas(createDefaultLayer: true) 33 | a.translatesAutoresizingMaskIntoConstraints = false 34 | a.backgroundColor = .white 35 | a.delegate = self 36 | 37 | return a 38 | }() 39 | 40 | 41 | 42 | 43 | lazy var colorBtn: UIButton = { 44 | let a = UIButton() 45 | a.translatesAutoresizingMaskIntoConstraints = false 46 | a.setTitle("Change Brush (Random)", for: .normal) 47 | a.backgroundColor = UIColor.gray 48 | a.addTarget(self, action: #selector(newColor), for: .touchUpInside) 49 | 50 | return a 51 | }() 52 | 53 | lazy var toolBtn: UIButton = { 54 | let a = UIButton() 55 | a.translatesAutoresizingMaskIntoConstraints = false 56 | a.setTitle("Change Tool (Random)", for: .normal) 57 | a.backgroundColor = UIColor.lightGray 58 | a.addTarget(self, action: #selector(newTool), for: .touchUpInside) 59 | 60 | return a 61 | }() 62 | 63 | lazy var undoBtn: UIButton = { 64 | let a = UIButton() 65 | a.translatesAutoresizingMaskIntoConstraints = false 66 | a.setTitle("Undo", for: .normal) 67 | a.backgroundColor = UIColor.lightGray 68 | a.addTarget(self, action: #selector(undo), for: .touchUpInside) 69 | 70 | return a 71 | }() 72 | 73 | lazy var redoBtn: UIButton = { 74 | let a = UIButton() 75 | a.translatesAutoresizingMaskIntoConstraints = false 76 | a.setTitle("Redo", for: .normal) 77 | a.backgroundColor = UIColor.gray 78 | a.addTarget(self, action: #selector(redo), for: .touchUpInside) 79 | 80 | return a 81 | }() 82 | 83 | lazy var clearBtn: UIButton = { 84 | let a = UIButton() 85 | a.translatesAutoresizingMaskIntoConstraints = false 86 | a.setTitle("Clear", for: .normal) 87 | a.backgroundColor = UIColor.gray 88 | a.addTarget(self, action: #selector(clear), for: .touchUpInside) 89 | 90 | return a 91 | }() 92 | 93 | lazy var addLayerBtn: UIButton = { 94 | let a = UIButton() 95 | a.translatesAutoresizingMaskIntoConstraints = false 96 | a.setTitle("Add Layer", for: .normal) 97 | a.backgroundColor = UIColor.lightGray 98 | a.addTarget(self, action: #selector(addLayer), for: .touchUpInside) 99 | 100 | return a 101 | }() 102 | 103 | lazy var switchLayerBtn: UIButton = { 104 | let a = UIButton() 105 | a.translatesAutoresizingMaskIntoConstraints = false 106 | a.setTitle("Switch Layer (Random)", for: .normal) 107 | a.backgroundColor = UIColor.gray 108 | a.addTarget(self, action: #selector(switchLayer), for: .touchUpInside) 109 | 110 | return a 111 | }() 112 | 113 | lazy var importBtn: UIButton = { 114 | let a = UIButton() 115 | a.translatesAutoresizingMaskIntoConstraints = false 116 | a.setTitle("Import Image", for: .normal) 117 | a.backgroundColor = UIColor.gray 118 | 119 | return a 120 | }() 121 | 122 | lazy var exportBtn: UIButton = { 123 | let a = UIButton() 124 | a.translatesAutoresizingMaskIntoConstraints = false 125 | a.setTitle("Export Image", for: .normal) 126 | a.backgroundColor = UIColor.lightGray 127 | a.addTarget(self, action: #selector(exportImage), for: .touchUpInside) 128 | 129 | return a 130 | }() 131 | 132 | lazy var selectBtn: UIButton = { 133 | let a = UIButton() 134 | a.translatesAutoresizingMaskIntoConstraints = false 135 | a.setTitle("Select Tool", for: .normal) 136 | a.backgroundColor = UIColor.lightGray 137 | a.addTarget(self, action: #selector(selectTool), for: .touchUpInside) 138 | 139 | return a 140 | }() 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | /************************ 152 | * * 153 | * INIT * 154 | * * 155 | ************************/ 156 | 157 | override func viewDidLoad() { 158 | super.viewDidLoad() 159 | view.backgroundColor = .brown 160 | canvasView.addSubview(canvas) 161 | view.addSubview(canvasView) 162 | view.addSubview(colorBtn) 163 | view.addSubview(undoBtn) 164 | view.addSubview(redoBtn) 165 | view.addSubview(clearBtn) 166 | view.addSubview(addLayerBtn) 167 | view.addSubview(switchLayerBtn) 168 | view.addSubview(toolBtn) 169 | view.addSubview(importBtn) 170 | view.addSubview(exportBtn) 171 | view.addSubview(selectBtn) 172 | 173 | setupLayout() 174 | 175 | let pinch = UIPinchGestureRecognizer(target: self, action: #selector(zoom(sender:))) 176 | view.addGestureRecognizer(pinch) 177 | } 178 | 179 | 180 | 181 | 182 | /************************ 183 | * * 184 | * DELEGATE * 185 | * * 186 | ************************/ 187 | 188 | func willBeginDrawing(on canvas: Canvas) { 189 | 190 | } 191 | 192 | func isDrawing(on canvas: Canvas) { 193 | 194 | } 195 | 196 | func didFinishDrawing(on canvas: Canvas) { 197 | 198 | } 199 | 200 | func didSampleColor(on canvas: Canvas, sampledColor color: UIColor) { 201 | 202 | } 203 | 204 | func didPaintNodes(on canvas: Canvas, nodes: [Node], strokeColor: UIColor, fillColor: UIColor?) { 205 | 206 | } 207 | 208 | func didUndo(on canvas: Canvas) { 209 | 210 | } 211 | 212 | func didRedo(on canvas: Canvas) { 213 | 214 | } 215 | 216 | func didCopyNodes(on canvas: Canvas, nodes: [Node]) { 217 | 218 | } 219 | 220 | func didPasteNodes(on canvas: Canvas, on layer: CanvasLayer, nodes: [Node]) { 221 | 222 | } 223 | 224 | func didSelectNodes(on canvas: Canvas, on layer: CanvasLayer, selectedNodes: [Node]) { 225 | 226 | } 227 | 228 | func didMoveNodes(on canvas: Canvas, movedNodes: [Node]) { 229 | 230 | } 231 | 232 | 233 | 234 | 235 | /************************ 236 | * * 237 | * FUNCTIONS * 238 | * * 239 | ************************/ 240 | 241 | @objc func newColor() { 242 | let colors: [UIColor] = [.green, .blue, .red, .purple, .black] 243 | let rand = Int(arc4random_uniform(UInt32(colors.count))) 244 | let nColor = colors[rand] 245 | canvas.currentBrush.strokeColor = nColor 246 | } 247 | 248 | @objc func newTool() { 249 | let tools: [CanvasTool] = [.pen, .eraser, .line, .rectangle, .ellipse, .eyedropper, .paint] 250 | let rand = Int(arc4random_uniform(UInt32(tools.count))) 251 | canvas.currentTool = tools[rand] 252 | print("tool: \(canvas.currentTool)") 253 | } 254 | 255 | @objc func selectTool() { 256 | canvas.currentTool = .selection 257 | } 258 | 259 | @objc func undo() { 260 | canvas.undo() 261 | } 262 | 263 | @objc func redo() { 264 | canvas.redo() 265 | } 266 | 267 | @objc func clear() { 268 | canvas.clear() 269 | } 270 | 271 | @objc func addLayer() { 272 | let rand = Int(arc4random_uniform(UInt32(2))) 273 | let layer = CanvasLayer(type: rand == 0 ? .raster : .vector) 274 | canvas.addLayer(newLayer: layer, position: .above) 275 | } 276 | 277 | @objc func switchLayer() { 278 | let rand = Int(arc4random_uniform(UInt32(canvas.canvasLayers.count))) 279 | canvas.switchLayer(to: rand) 280 | } 281 | 282 | @objc func exportImage() { 283 | let exp = canvas.export() 284 | UIImageWriteToSavedPhotosAlbum(exp, nil, nil, nil) 285 | } 286 | 287 | 288 | func alert(title: String, message: String) { 289 | let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertController.Style.alert) 290 | alert.addAction(UIAlertAction(title: "Ok", style: UIAlertAction.Style.cancel, handler: nil)) 291 | self.show(alert, sender: self) 292 | } 293 | 294 | 295 | 296 | /************************ 297 | * * 298 | * LAYOUT * 299 | * * 300 | ************************/ 301 | 302 | @objc func zoom(sender: UIPinchGestureRecognizer) { 303 | let transform = canvas.transform.scaledBy(x: sender.scale, y: sender.scale) 304 | canvas.transform = transform 305 | sender.scale = 1.0 306 | } 307 | 308 | 309 | func setupLayout() { 310 | canvasView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true 311 | canvasView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true 312 | canvasView.widthAnchor.constraint(equalTo: view.widthAnchor).isActive = true 313 | canvasView.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.7).isActive = true 314 | 315 | canvas.centerXAnchor.constraint(equalTo: canvasView.centerXAnchor).isActive = true 316 | canvas.topAnchor.constraint(equalTo: canvasView.topAnchor).isActive = true 317 | canvas.widthAnchor.constraint(equalTo: canvasView.widthAnchor).isActive = true 318 | canvas.heightAnchor.constraint(equalTo: canvasView.heightAnchor).isActive = true 319 | 320 | colorBtn.topAnchor.constraint(equalTo: canvasView.bottomAnchor).isActive = true 321 | colorBtn.leadingAnchor.constraint(equalTo: canvasView.leadingAnchor).isActive = true 322 | colorBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 323 | colorBtn.heightAnchor.constraint(equalToConstant: 60).isActive = true 324 | 325 | undoBtn.topAnchor.constraint(equalTo: colorBtn.bottomAnchor).isActive = true 326 | undoBtn.leadingAnchor.constraint(equalTo: canvasView.leadingAnchor).isActive = true 327 | undoBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 328 | undoBtn.heightAnchor.constraint(equalToConstant: 60).isActive = true 329 | 330 | redoBtn.topAnchor.constraint(equalTo: undoBtn.bottomAnchor).isActive = true 331 | redoBtn.leadingAnchor.constraint(equalTo: canvasView.leadingAnchor).isActive = true 332 | redoBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 333 | redoBtn.heightAnchor.constraint(equalToConstant: 60).isActive = true 334 | 335 | addLayerBtn.topAnchor.constraint(equalTo: redoBtn.bottomAnchor).isActive = true 336 | addLayerBtn.leadingAnchor.constraint(equalTo: canvasView.leadingAnchor).isActive = true 337 | addLayerBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 338 | addLayerBtn.heightAnchor.constraint(equalToConstant: 60).isActive = true 339 | 340 | switchLayerBtn.topAnchor.constraint(equalTo: addLayerBtn.bottomAnchor).isActive = true 341 | switchLayerBtn.leadingAnchor.constraint(equalTo: canvasView.leadingAnchor).isActive = true 342 | switchLayerBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 343 | switchLayerBtn.heightAnchor.constraint(equalToConstant: 67).isActive = true 344 | 345 | toolBtn.topAnchor.constraint(equalTo: canvasView.bottomAnchor).isActive = true 346 | toolBtn.leadingAnchor.constraint(equalTo: colorBtn.trailingAnchor).isActive = true 347 | toolBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 348 | toolBtn.heightAnchor.constraint(equalToConstant: 60).isActive = true 349 | 350 | importBtn.topAnchor.constraint(equalTo: toolBtn.bottomAnchor).isActive = true 351 | importBtn.leadingAnchor.constraint(equalTo: colorBtn.trailingAnchor).isActive = true 352 | importBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 353 | importBtn.heightAnchor.constraint(equalToConstant: 60).isActive = true 354 | 355 | exportBtn.topAnchor.constraint(equalTo: importBtn.bottomAnchor).isActive = true 356 | exportBtn.leadingAnchor.constraint(equalTo: colorBtn.trailingAnchor).isActive = true 357 | exportBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 358 | exportBtn.heightAnchor.constraint(equalToConstant: 60).isActive = true 359 | 360 | clearBtn.topAnchor.constraint(equalTo: exportBtn.bottomAnchor).isActive = true 361 | clearBtn.leadingAnchor.constraint(equalTo: colorBtn.trailingAnchor).isActive = true 362 | clearBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 363 | clearBtn.heightAnchor.constraint(equalToConstant: 60).isActive = true 364 | 365 | selectBtn.topAnchor.constraint(equalTo: clearBtn.bottomAnchor).isActive = true 366 | selectBtn.leadingAnchor.constraint(equalTo: colorBtn.trailingAnchor).isActive = true 367 | selectBtn.widthAnchor.constraint(equalTo: canvasView.widthAnchor, multiplier: 0.5).isActive = true 368 | selectBtn.heightAnchor.constraint(equalToConstant: 67).isActive = true 369 | } 370 | 371 | 372 | } 373 | 374 | -------------------------------------------------------------------------------- /Example/Podfile: -------------------------------------------------------------------------------- 1 | use_frameworks! 2 | 3 | target 'Canvas_Example' do 4 | pod 'Canvas', :path => '../' 5 | 6 | target 'Canvas_Tests' do 7 | inherit! :search_paths 8 | 9 | 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /Example/Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Canvas (0.1.0) 3 | 4 | DEPENDENCIES: 5 | - Canvas (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | Canvas: 9 | :path: ../ 10 | 11 | SPEC CHECKSUMS: 12 | Canvas: a4bb0fe09e3fd487d48b339b2806980b8844dc65 13 | 14 | PODFILE CHECKSUM: 8894004838d689237ea4aeda48d69bece4c83a36 15 | 16 | COCOAPODS: 1.4.0 17 | -------------------------------------------------------------------------------- /Example/Pods/Local Podspecs/Canvas.podspec.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Canvas", 3 | "version": "0.1.0", 4 | "summary": "A short description of Canvas.", 5 | "description": "TODO: Add long description of the pod here.", 6 | "homepage": "https://github.com/authman2/Canvas", 7 | "license": { 8 | "type": "MIT", 9 | "file": "LICENSE" 10 | }, 11 | "authors": { 12 | "authman2": "authman2@gmail.com" 13 | }, 14 | "source": { 15 | "git": "https://github.com/authman2/Canvas.git", 16 | "tag": "0.1.0" 17 | }, 18 | "platforms": { 19 | "ios": "8.0" 20 | }, 21 | "source_files": "Canvas/Classes/**/*" 22 | } 23 | -------------------------------------------------------------------------------- /Example/Pods/Manifest.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - Canvas (0.1.0) 3 | 4 | DEPENDENCIES: 5 | - Canvas (from `../`) 6 | 7 | EXTERNAL SOURCES: 8 | Canvas: 9 | :path: ../ 10 | 11 | SPEC CHECKSUMS: 12 | Canvas: a4bb0fe09e3fd487d48b339b2806980b8844dc65 13 | 14 | PODFILE CHECKSUM: 8894004838d689237ea4aeda48d69bece4c83a36 15 | 16 | COCOAPODS: 1.4.0 17 | -------------------------------------------------------------------------------- /Example/Pods/Pods.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Pods/Pods.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Canvas/Canvas-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Canvas : NSObject 3 | @end 4 | @implementation PodsDummy_Canvas 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Canvas/Canvas-prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Canvas/Canvas-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double CanvasVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char CanvasVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Canvas/Canvas.modulemap: -------------------------------------------------------------------------------- 1 | framework module Canvas { 2 | umbrella header "Canvas-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Canvas/Canvas.xcconfig: -------------------------------------------------------------------------------- 1 | CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/Canvas 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | HEADER_SEARCH_PATHS = "${PODS_ROOT}/Headers/Private" "${PODS_ROOT}/Headers/Public" 4 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_ROOT = ${SRCROOT} 8 | PODS_TARGET_SRCROOT = ${PODS_ROOT}/../.. 9 | PRODUCT_BUNDLE_IDENTIFIER = org.cocoapods.${PRODUCT_NAME:rfc1034identifier} 10 | SKIP_INSTALL = YES 11 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Canvas/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 0.1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | 4 | ## Canvas 5 | 6 | Copyright (c) 2018 authman2 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in 16 | all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 | THE SOFTWARE. 25 | 26 | Generated by CocoaPods - https://cocoapods.org 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Copyright (c) 2018 authman2 <authman2@gmail.com> 18 | 19 | Permission is hereby granted, free of charge, to any person obtaining a copy 20 | of this software and associated documentation files (the "Software"), to deal 21 | in the Software without restriction, including without limitation the rights 22 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 23 | copies of the Software, and to permit persons to whom the Software is 24 | furnished to do so, subject to the following conditions: 25 | 26 | The above copyright notice and this permission notice shall be included in 27 | all copies or substantial portions of the Software. 28 | 29 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 32 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 33 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 34 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 35 | THE SOFTWARE. 36 | 37 | License 38 | MIT 39 | Title 40 | Canvas 41 | Type 42 | PSGroupSpecifier 43 | 44 | 45 | FooterText 46 | Generated by CocoaPods - https://cocoapods.org 47 | Title 48 | 49 | Type 50 | PSGroupSpecifier 51 | 52 | 53 | StringsTable 54 | Acknowledgements 55 | Title 56 | Acknowledgements 57 | 58 | 59 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_Canvas_Example : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_Canvas_Example 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 5 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 6 | 7 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 8 | 9 | # Used as a return value for each invocation of `strip_invalid_archs` function. 10 | STRIP_BINARY_RETVAL=0 11 | 12 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 13 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 14 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 15 | 16 | # Copies and strips a vendored framework 17 | install_framework() 18 | { 19 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 20 | local source="${BUILT_PRODUCTS_DIR}/$1" 21 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 22 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 23 | elif [ -r "$1" ]; then 24 | local source="$1" 25 | fi 26 | 27 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 28 | 29 | if [ -L "${source}" ]; then 30 | echo "Symlinked..." 31 | source="$(readlink "${source}")" 32 | fi 33 | 34 | # Use filter instead of exclude so missing patterns don't throw errors. 35 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 36 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 37 | 38 | local basename 39 | basename="$(basename -s .framework "$1")" 40 | binary="${destination}/${basename}.framework/${basename}" 41 | if ! [ -r "$binary" ]; then 42 | binary="${destination}/${basename}" 43 | fi 44 | 45 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 46 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 47 | strip_invalid_archs "$binary" 48 | fi 49 | 50 | # Resign the code if required by the build settings to avoid unstable apps 51 | code_sign_if_enabled "${destination}/$(basename "$1")" 52 | 53 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 54 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 55 | local swift_runtime_libs 56 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) 57 | for lib in $swift_runtime_libs; do 58 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 59 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 60 | code_sign_if_enabled "${destination}/${lib}" 61 | done 62 | fi 63 | } 64 | 65 | # Copies and strips a vendored dSYM 66 | install_dsym() { 67 | local source="$1" 68 | if [ -r "$source" ]; then 69 | # Copy the dSYM into a the targets temp dir. 70 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DERIVED_FILES_DIR}\"" 71 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}" 72 | 73 | local basename 74 | basename="$(basename -s .framework.dSYM "$source")" 75 | binary="${DERIVED_FILES_DIR}/${basename}.framework.dSYM/Contents/Resources/DWARF/${basename}" 76 | 77 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 78 | if [[ "$(file "$binary")" == *"Mach-O dSYM companion"* ]]; then 79 | strip_invalid_archs "$binary" 80 | fi 81 | 82 | if [[ $STRIP_BINARY_RETVAL == 1 ]]; then 83 | # Move the stripped file into its final destination. 84 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\"" 85 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.framework.dSYM" "${DWARF_DSYM_FOLDER_PATH}" 86 | else 87 | # The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing. 88 | touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.framework.dSYM" 89 | fi 90 | fi 91 | } 92 | 93 | # Signs a framework with the provided identity 94 | code_sign_if_enabled() { 95 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 96 | # Use the current code_sign_identitiy 97 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 98 | local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements '$1'" 99 | 100 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 101 | code_sign_cmd="$code_sign_cmd &" 102 | fi 103 | echo "$code_sign_cmd" 104 | eval "$code_sign_cmd" 105 | fi 106 | } 107 | 108 | # Strip invalid architectures 109 | strip_invalid_archs() { 110 | binary="$1" 111 | # Get architectures for current target binary 112 | binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)" 113 | # Intersect them with the architectures we are building for 114 | intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)" 115 | # If there are no archs supported by this binary then warn the user 116 | if [[ -z "$intersected_archs" ]]; then 117 | echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)." 118 | STRIP_BINARY_RETVAL=0 119 | return 120 | fi 121 | stripped="" 122 | for arch in $binary_archs; do 123 | if ! [[ "${ARCHS}" == *"$arch"* ]]; then 124 | # Strip non-valid architectures in-place 125 | lipo -remove "$arch" -output "$binary" "$binary" || exit 1 126 | stripped="$stripped $arch" 127 | fi 128 | done 129 | if [[ "$stripped" ]]; then 130 | echo "Stripped $binary of architectures:$stripped" 131 | fi 132 | STRIP_BINARY_RETVAL=1 133 | } 134 | 135 | 136 | if [[ "$CONFIGURATION" == "Debug" ]]; then 137 | install_framework "${BUILT_PRODUCTS_DIR}/Canvas/Canvas.framework" 138 | fi 139 | if [[ "$CONFIGURATION" == "Release" ]]; then 140 | install_framework "${BUILT_PRODUCTS_DIR}/Canvas/Canvas.framework" 141 | fi 142 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 143 | wait 144 | fi 145 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example-resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 5 | 6 | RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt 7 | > "$RESOURCES_TO_COPY" 8 | 9 | XCASSET_FILES=() 10 | 11 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 12 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 13 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 14 | 15 | case "${TARGETED_DEVICE_FAMILY}" in 16 | 1,2) 17 | TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" 18 | ;; 19 | 1) 20 | TARGET_DEVICE_ARGS="--target-device iphone" 21 | ;; 22 | 2) 23 | TARGET_DEVICE_ARGS="--target-device ipad" 24 | ;; 25 | 3) 26 | TARGET_DEVICE_ARGS="--target-device tv" 27 | ;; 28 | 4) 29 | TARGET_DEVICE_ARGS="--target-device watch" 30 | ;; 31 | *) 32 | TARGET_DEVICE_ARGS="--target-device mac" 33 | ;; 34 | esac 35 | 36 | install_resource() 37 | { 38 | if [[ "$1" = /* ]] ; then 39 | RESOURCE_PATH="$1" 40 | else 41 | RESOURCE_PATH="${PODS_ROOT}/$1" 42 | fi 43 | if [[ ! -e "$RESOURCE_PATH" ]] ; then 44 | cat << EOM 45 | error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script. 46 | EOM 47 | exit 1 48 | fi 49 | case $RESOURCE_PATH in 50 | *.storyboard) 51 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true 52 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 53 | ;; 54 | *.xib) 55 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true 56 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 57 | ;; 58 | *.framework) 59 | echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true 60 | mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 61 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true 62 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 63 | ;; 64 | *.xcdatamodel) 65 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\"" || true 66 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom" 67 | ;; 68 | *.xcdatamodeld) 69 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\"" || true 70 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd" 71 | ;; 72 | *.xcmappingmodel) 73 | echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\"" || true 74 | xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm" 75 | ;; 76 | *.xcassets) 77 | ABSOLUTE_XCASSET_FILE="$RESOURCE_PATH" 78 | XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") 79 | ;; 80 | *) 81 | echo "$RESOURCE_PATH" || true 82 | echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY" 83 | ;; 84 | esac 85 | } 86 | 87 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 88 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 89 | if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then 90 | mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 91 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 92 | fi 93 | rm -f "$RESOURCES_TO_COPY" 94 | 95 | if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] 96 | then 97 | # Find all other xcassets (this unfortunately includes those of path pods and other targets). 98 | OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) 99 | while read line; do 100 | if [[ $line != "${PODS_ROOT}*" ]]; then 101 | XCASSET_FILES+=("$line") 102 | fi 103 | done <<<"$OTHER_XCASSETS" 104 | 105 | printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 106 | fi 107 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_Canvas_ExampleVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_Canvas_ExampleVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example.debug.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/Canvas" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 5 | OTHER_CFLAGS = $(inherited) -iquote "${PODS_CONFIGURATION_BUILD_DIR}/Canvas/Canvas.framework/Headers" 6 | OTHER_LDFLAGS = $(inherited) -framework "Canvas" 7 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 8 | PODS_BUILD_DIR = ${BUILD_DIR} 9 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 10 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 11 | PODS_ROOT = ${SRCROOT}/Pods 12 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_Canvas_Example { 2 | umbrella header "Pods-Canvas_Example-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Example/Pods-Canvas_Example.release.xcconfig: -------------------------------------------------------------------------------- 1 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES 2 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/Canvas" 3 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 4 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 5 | OTHER_CFLAGS = $(inherited) -iquote "${PODS_CONFIGURATION_BUILD_DIR}/Canvas/Canvas.framework/Headers" 6 | OTHER_LDFLAGS = $(inherited) -framework "Canvas" 7 | OTHER_SWIFT_FLAGS = $(inherited) "-D" "COCOAPODS" 8 | PODS_BUILD_DIR = ${BUILD_DIR} 9 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 10 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 11 | PODS_ROOT = ${SRCROOT}/Pods 12 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | ${PRODUCT_BUNDLE_IDENTIFIER} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | ${PRODUCT_NAME} 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | ${CURRENT_PROJECT_VERSION} 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests-acknowledgements.markdown: -------------------------------------------------------------------------------- 1 | # Acknowledgements 2 | This application makes use of the following third party libraries: 3 | Generated by CocoaPods - https://cocoapods.org 4 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests-acknowledgements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PreferenceSpecifiers 6 | 7 | 8 | FooterText 9 | This application makes use of the following third party libraries: 10 | Title 11 | Acknowledgements 12 | Type 13 | PSGroupSpecifier 14 | 15 | 16 | FooterText 17 | Generated by CocoaPods - https://cocoapods.org 18 | Title 19 | 20 | Type 21 | PSGroupSpecifier 22 | 23 | 24 | StringsTable 25 | Acknowledgements 26 | Title 27 | Acknowledgements 28 | 29 | 30 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests-dummy.m: -------------------------------------------------------------------------------- 1 | #import 2 | @interface PodsDummy_Pods_Canvas_Tests : NSObject 3 | @end 4 | @implementation PodsDummy_Pods_Canvas_Tests 5 | @end 6 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests-frameworks.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | echo "mkdir -p ${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 5 | mkdir -p "${CONFIGURATION_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 6 | 7 | SWIFT_STDLIB_PATH="${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" 8 | 9 | # Used as a return value for each invocation of `strip_invalid_archs` function. 10 | STRIP_BINARY_RETVAL=0 11 | 12 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 13 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 14 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 15 | 16 | # Copies and strips a vendored framework 17 | install_framework() 18 | { 19 | if [ -r "${BUILT_PRODUCTS_DIR}/$1" ]; then 20 | local source="${BUILT_PRODUCTS_DIR}/$1" 21 | elif [ -r "${BUILT_PRODUCTS_DIR}/$(basename "$1")" ]; then 22 | local source="${BUILT_PRODUCTS_DIR}/$(basename "$1")" 23 | elif [ -r "$1" ]; then 24 | local source="$1" 25 | fi 26 | 27 | local destination="${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 28 | 29 | if [ -L "${source}" ]; then 30 | echo "Symlinked..." 31 | source="$(readlink "${source}")" 32 | fi 33 | 34 | # Use filter instead of exclude so missing patterns don't throw errors. 35 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${destination}\"" 36 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${destination}" 37 | 38 | local basename 39 | basename="$(basename -s .framework "$1")" 40 | binary="${destination}/${basename}.framework/${basename}" 41 | if ! [ -r "$binary" ]; then 42 | binary="${destination}/${basename}" 43 | fi 44 | 45 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 46 | if [[ "$(file "$binary")" == *"dynamically linked shared library"* ]]; then 47 | strip_invalid_archs "$binary" 48 | fi 49 | 50 | # Resign the code if required by the build settings to avoid unstable apps 51 | code_sign_if_enabled "${destination}/$(basename "$1")" 52 | 53 | # Embed linked Swift runtime libraries. No longer necessary as of Xcode 7. 54 | if [ "${XCODE_VERSION_MAJOR}" -lt 7 ]; then 55 | local swift_runtime_libs 56 | swift_runtime_libs=$(xcrun otool -LX "$binary" | grep --color=never @rpath/libswift | sed -E s/@rpath\\/\(.+dylib\).*/\\1/g | uniq -u && exit ${PIPESTATUS[0]}) 57 | for lib in $swift_runtime_libs; do 58 | echo "rsync -auv \"${SWIFT_STDLIB_PATH}/${lib}\" \"${destination}\"" 59 | rsync -auv "${SWIFT_STDLIB_PATH}/${lib}" "${destination}" 60 | code_sign_if_enabled "${destination}/${lib}" 61 | done 62 | fi 63 | } 64 | 65 | # Copies and strips a vendored dSYM 66 | install_dsym() { 67 | local source="$1" 68 | if [ -r "$source" ]; then 69 | # Copy the dSYM into a the targets temp dir. 70 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${source}\" \"${DERIVED_FILES_DIR}\"" 71 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${source}" "${DERIVED_FILES_DIR}" 72 | 73 | local basename 74 | basename="$(basename -s .framework.dSYM "$source")" 75 | binary="${DERIVED_FILES_DIR}/${basename}.framework.dSYM/Contents/Resources/DWARF/${basename}" 76 | 77 | # Strip invalid architectures so "fat" simulator / device frameworks work on device 78 | if [[ "$(file "$binary")" == *"Mach-O dSYM companion"* ]]; then 79 | strip_invalid_archs "$binary" 80 | fi 81 | 82 | if [[ $STRIP_BINARY_RETVAL == 1 ]]; then 83 | # Move the stripped file into its final destination. 84 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter \"- CVS/\" --filter \"- .svn/\" --filter \"- .git/\" --filter \"- .hg/\" --filter \"- Headers\" --filter \"- PrivateHeaders\" --filter \"- Modules\" \"${DERIVED_FILES_DIR}/${basename}.framework.dSYM\" \"${DWARF_DSYM_FOLDER_PATH}\"" 85 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" --filter "- CVS/" --filter "- .svn/" --filter "- .git/" --filter "- .hg/" --filter "- Headers" --filter "- PrivateHeaders" --filter "- Modules" "${DERIVED_FILES_DIR}/${basename}.framework.dSYM" "${DWARF_DSYM_FOLDER_PATH}" 86 | else 87 | # The dSYM was not stripped at all, in this case touch a fake folder so the input/output paths from Xcode do not reexecute this script because the file is missing. 88 | touch "${DWARF_DSYM_FOLDER_PATH}/${basename}.framework.dSYM" 89 | fi 90 | fi 91 | } 92 | 93 | # Signs a framework with the provided identity 94 | code_sign_if_enabled() { 95 | if [ -n "${EXPANDED_CODE_SIGN_IDENTITY}" -a "${CODE_SIGNING_REQUIRED}" != "NO" -a "${CODE_SIGNING_ALLOWED}" != "NO" ]; then 96 | # Use the current code_sign_identitiy 97 | echo "Code Signing $1 with Identity ${EXPANDED_CODE_SIGN_IDENTITY_NAME}" 98 | local code_sign_cmd="/usr/bin/codesign --force --sign ${EXPANDED_CODE_SIGN_IDENTITY} ${OTHER_CODE_SIGN_FLAGS} --preserve-metadata=identifier,entitlements '$1'" 99 | 100 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 101 | code_sign_cmd="$code_sign_cmd &" 102 | fi 103 | echo "$code_sign_cmd" 104 | eval "$code_sign_cmd" 105 | fi 106 | } 107 | 108 | # Strip invalid architectures 109 | strip_invalid_archs() { 110 | binary="$1" 111 | # Get architectures for current target binary 112 | binary_archs="$(lipo -info "$binary" | rev | cut -d ':' -f1 | awk '{$1=$1;print}' | rev)" 113 | # Intersect them with the architectures we are building for 114 | intersected_archs="$(echo ${ARCHS[@]} ${binary_archs[@]} | tr ' ' '\n' | sort | uniq -d)" 115 | # If there are no archs supported by this binary then warn the user 116 | if [[ -z "$intersected_archs" ]]; then 117 | echo "warning: [CP] Vendored binary '$binary' contains architectures ($binary_archs) none of which match the current build architectures ($ARCHS)." 118 | STRIP_BINARY_RETVAL=0 119 | return 120 | fi 121 | stripped="" 122 | for arch in $binary_archs; do 123 | if ! [[ "${ARCHS}" == *"$arch"* ]]; then 124 | # Strip non-valid architectures in-place 125 | lipo -remove "$arch" -output "$binary" "$binary" || exit 1 126 | stripped="$stripped $arch" 127 | fi 128 | done 129 | if [[ "$stripped" ]]; then 130 | echo "Stripped $binary of architectures:$stripped" 131 | fi 132 | STRIP_BINARY_RETVAL=1 133 | } 134 | 135 | if [ "${COCOAPODS_PARALLEL_CODE_SIGN}" == "true" ]; then 136 | wait 137 | fi 138 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests-resources.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 5 | 6 | RESOURCES_TO_COPY=${PODS_ROOT}/resources-to-copy-${TARGETNAME}.txt 7 | > "$RESOURCES_TO_COPY" 8 | 9 | XCASSET_FILES=() 10 | 11 | # This protects against multiple targets copying the same framework dependency at the same time. The solution 12 | # was originally proposed here: https://lists.samba.org/archive/rsync/2008-February/020158.html 13 | RSYNC_PROTECT_TMP_FILES=(--filter "P .*.??????") 14 | 15 | case "${TARGETED_DEVICE_FAMILY}" in 16 | 1,2) 17 | TARGET_DEVICE_ARGS="--target-device ipad --target-device iphone" 18 | ;; 19 | 1) 20 | TARGET_DEVICE_ARGS="--target-device iphone" 21 | ;; 22 | 2) 23 | TARGET_DEVICE_ARGS="--target-device ipad" 24 | ;; 25 | 3) 26 | TARGET_DEVICE_ARGS="--target-device tv" 27 | ;; 28 | 4) 29 | TARGET_DEVICE_ARGS="--target-device watch" 30 | ;; 31 | *) 32 | TARGET_DEVICE_ARGS="--target-device mac" 33 | ;; 34 | esac 35 | 36 | install_resource() 37 | { 38 | if [[ "$1" = /* ]] ; then 39 | RESOURCE_PATH="$1" 40 | else 41 | RESOURCE_PATH="${PODS_ROOT}/$1" 42 | fi 43 | if [[ ! -e "$RESOURCE_PATH" ]] ; then 44 | cat << EOM 45 | error: Resource "$RESOURCE_PATH" not found. Run 'pod install' to update the copy resources script. 46 | EOM 47 | exit 1 48 | fi 49 | case $RESOURCE_PATH in 50 | *.storyboard) 51 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true 52 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .storyboard`.storyboardc" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 53 | ;; 54 | *.xib) 55 | echo "ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile ${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib $RESOURCE_PATH --sdk ${SDKROOT} ${TARGET_DEVICE_ARGS}" || true 56 | ibtool --reference-external-strings-file --errors --warnings --notices --minimum-deployment-target ${!DEPLOYMENT_TARGET_SETTING_NAME} --output-format human-readable-text --compile "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename \"$RESOURCE_PATH\" .xib`.nib" "$RESOURCE_PATH" --sdk "${SDKROOT}" ${TARGET_DEVICE_ARGS} 57 | ;; 58 | *.framework) 59 | echo "mkdir -p ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true 60 | mkdir -p "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 61 | echo "rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" $RESOURCE_PATH ${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" || true 62 | rsync --delete -av "${RSYNC_PROTECT_TMP_FILES[@]}" "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}" 63 | ;; 64 | *.xcdatamodel) 65 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH"`.mom\"" || true 66 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodel`.mom" 67 | ;; 68 | *.xcdatamodeld) 69 | echo "xcrun momc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd\"" || true 70 | xcrun momc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcdatamodeld`.momd" 71 | ;; 72 | *.xcmappingmodel) 73 | echo "xcrun mapc \"$RESOURCE_PATH\" \"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm\"" || true 74 | xcrun mapc "$RESOURCE_PATH" "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/`basename "$RESOURCE_PATH" .xcmappingmodel`.cdm" 75 | ;; 76 | *.xcassets) 77 | ABSOLUTE_XCASSET_FILE="$RESOURCE_PATH" 78 | XCASSET_FILES+=("$ABSOLUTE_XCASSET_FILE") 79 | ;; 80 | *) 81 | echo "$RESOURCE_PATH" || true 82 | echo "$RESOURCE_PATH" >> "$RESOURCES_TO_COPY" 83 | ;; 84 | esac 85 | } 86 | 87 | mkdir -p "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 88 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 89 | if [[ "${ACTION}" == "install" ]] && [[ "${SKIP_INSTALL}" == "NO" ]]; then 90 | mkdir -p "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 91 | rsync -avr --copy-links --no-relative --exclude '*/.svn/*' --files-from="$RESOURCES_TO_COPY" / "${INSTALL_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 92 | fi 93 | rm -f "$RESOURCES_TO_COPY" 94 | 95 | if [[ -n "${WRAPPER_EXTENSION}" ]] && [ "`xcrun --find actool`" ] && [ -n "$XCASSET_FILES" ] 96 | then 97 | # Find all other xcassets (this unfortunately includes those of path pods and other targets). 98 | OTHER_XCASSETS=$(find "$PWD" -iname "*.xcassets" -type d) 99 | while read line; do 100 | if [[ $line != "${PODS_ROOT}*" ]]; then 101 | XCASSET_FILES+=("$line") 102 | fi 103 | done <<<"$OTHER_XCASSETS" 104 | 105 | printf "%s\0" "${XCASSET_FILES[@]}" | xargs -0 xcrun actool --output-format human-readable-text --notices --warnings --platform "${PLATFORM_NAME}" --minimum-deployment-target "${!DEPLOYMENT_TARGET_SETTING_NAME}" ${TARGET_DEVICE_ARGS} --compress-pngs --compile "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}" 106 | fi 107 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests-umbrella.h: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #else 4 | #ifndef FOUNDATION_EXPORT 5 | #if defined(__cplusplus) 6 | #define FOUNDATION_EXPORT extern "C" 7 | #else 8 | #define FOUNDATION_EXPORT extern 9 | #endif 10 | #endif 11 | #endif 12 | 13 | 14 | FOUNDATION_EXPORT double Pods_Canvas_TestsVersionNumber; 15 | FOUNDATION_EXPORT const unsigned char Pods_Canvas_TestsVersionString[]; 16 | 17 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests.debug.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/Canvas" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 4 | OTHER_CFLAGS = $(inherited) -iquote "${PODS_CONFIGURATION_BUILD_DIR}/Canvas/Canvas.framework/Headers" 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 8 | PODS_ROOT = ${SRCROOT}/Pods 9 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests.modulemap: -------------------------------------------------------------------------------- 1 | framework module Pods_Canvas_Tests { 2 | umbrella header "Pods-Canvas_Tests-umbrella.h" 3 | 4 | export * 5 | module * { export * } 6 | } 7 | -------------------------------------------------------------------------------- /Example/Pods/Target Support Files/Pods-Canvas_Tests/Pods-Canvas_Tests.release.xcconfig: -------------------------------------------------------------------------------- 1 | FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/Canvas" 2 | GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 3 | LD_RUNPATH_SEARCH_PATHS = $(inherited) '@executable_path/Frameworks' '@loader_path/Frameworks' 4 | OTHER_CFLAGS = $(inherited) -iquote "${PODS_CONFIGURATION_BUILD_DIR}/Canvas/Canvas.framework/Headers" 5 | PODS_BUILD_DIR = ${BUILD_DIR} 6 | PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME) 7 | PODS_PODFILE_DIR_PATH = ${SRCROOT}/. 8 | PODS_ROOT = ${SRCROOT}/Pods 9 | -------------------------------------------------------------------------------- /Example/Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /Example/Tests/Tests.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | import XCTest 3 | import Canvas 4 | 5 | class Tests: XCTestCase { 6 | 7 | override func setUp() { 8 | super.setUp() 9 | // Put setup code here. This method is called before the invocation of each test method in the class. 10 | } 11 | 12 | override func tearDown() { 13 | // Put teardown code here. This method is called after the invocation of each test method in the class. 14 | super.tearDown() 15 | } 16 | 17 | func testExample() { 18 | // This is an example of a functional test case. 19 | XCTAssert(true, "Pass") 20 | } 21 | 22 | func testPerformanceExample() { 23 | // This is an example of a performance test case. 24 | self.measure() { 25 | // Put the code you want to measure the time of here. 26 | } 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 authman2 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #   Canvas 2 | 3 | [![Version](https://img.shields.io/cocoapods/v/Canvas.svg?style=flat)](http://cocoapods.org/pods/Canvas+) 4 | [![License](https://img.shields.io/cocoapods/l/Canvas.svg?style=flat)](http://cocoapods.org/pods/Canvas+) 5 | [![Platform](https://img.shields.io/cocoapods/p/Canvas.svg?style=flat)](http://cocoapods.org/pods/Canvas+) 6 | 7 | Canvas is an iOS library that creates an area on the screen where the user can draw lines and shapes, style drawings by adding different types of brushes, and work with multiple layers. It provides an easy way to add on-screen drawing to any iOS app. Canvas uses SVG and Raster graphics for drawing. 8 | 9 | ## Features 10 | - **Canvas**: A UIView with a clear background where users can draw. 11 | - **CanvasTools**: Draw using different shapes (pen, eraser, line, rectangle, ellipse, and eyedropper) 12 | - **CanvasLayers**: Create multiple SVG or Raster layers that can be moved, swapped, hidden, locked, and more. 13 | - **Brushes**: Create and use different brushes to style drawings on the canvas. 14 | - **CanvasEvents**: Keep track of when the user starts drawing, is drawing, and finishes drawing by using the CanvasEvents protocol. 15 | - **Export**: Export your canvas drawing as a UIImage. 16 | - **Undo/Redo/Clear**: Support for undo, redo, and clearing of drawings. You can also define for yourself what actions in your app should count toward to the undo/redo stack by using the addCustomUndoRedo function. 17 | - **Selection Tool**: Select different drawing strokes and move them around the canvas. Drawings can also be copied and pasted onto different canvas layers. 18 | 19 | ## Installation 20 | 21 | Canvas is available through [CocoaPods](http://cocoapods.org). To install 22 | it, simply add the following line to your Podfile: 23 | 24 | ```ruby 25 | pod 'Canvas+' 26 | ``` 27 | 28 | ## Author 29 | - Year: 2018 30 | - Languages/Tools: Swift 31 | - Programmer: Adeola Uthman 32 | 33 | ## License 34 | 35 | Canvas is available under the MIT license. See the LICENSE file for more info. 36 | 37 | 38 | -------------------------------------------------------------------------------- /_Pods.xcodeproj: -------------------------------------------------------------------------------- 1 | Example/Pods/Pods.xcodeproj --------------------------------------------------------------------------------