Skip to content

Commit

Permalink
Merge pull request #5 from mrazam110/master
Browse files Browse the repository at this point in the history
Awalz#53 Xcode 14 support
  • Loading branch information
metabren authored Dec 5, 2022
2 parents f9cb6cc + aaa2aa6 commit 3bd8dfd
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions Source/SwiftyDraw.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ import UIKit
func swiftyDraw(didCancelDrawingIn drawingView: SwiftyDrawView, using touch: UITouch)
}

protocol PencilInteractionSupport {
@available(iOS 12.1, *)
var delegate: UIPencilInteractionDelegate? { get set }
var isEnabled: Bool { get set }
}

@available(iOS 12.1, *)
extension UIPencilInteraction: PencilInteractionSupport {}

/// UIView Subclass where touch gestures are translated into Core Graphics drawing
open class SwiftyDrawView: UIView {

Expand All @@ -81,14 +90,13 @@ open class SwiftyDrawView: UIView {
public var isPencilInteractive : Bool = true {
didSet {
if #available(iOS 12.1, *) {
pencilInteraction.isEnabled = isPencilInteractive
pencilInteraction?.isEnabled = isPencilInteractive
}
}
}
/// Public SwiftyDrawView delegate
@IBOutlet public weak var delegate: SwiftyDrawViewDelegate?

@available(iOS 9.1, *)
public enum TouchType: Equatable, CaseIterable {
case finger, pencil

Expand All @@ -97,12 +105,15 @@ open class SwiftyDrawView: UIView {
case .finger:
return [.direct, .indirect]
case .pencil:
return [.pencil, .stylus ]
if #available(iOS 9.1, *) {
return [.pencil, .stylus]
} else {
return []
}
}
}
}
/// Determines which touch types are allowed to draw; default: `[.finger, .pencil]` (all)
@available(iOS 9.1, *)
public lazy var allowedTouchTypes: [TouchType] = [.finger, .pencil]

public var drawItems: [DrawItem] = []
Expand All @@ -113,8 +124,7 @@ open class SwiftyDrawView: UIView {
private var previousPreviousPoint: CGPoint = .zero

// For pencil interactions
@available(iOS 12.1, *)
lazy private var pencilInteraction = UIPencilInteraction()
private var pencilInteraction: PencilInteractionSupport?

/// Save the previous brush for Apple Pencil interaction Switch to previous tool
private var previousBrush: Brush = .default
Expand All @@ -139,8 +149,10 @@ open class SwiftyDrawView: UIView {
self.backgroundColor = .clear
// receive pencil interaction if supported
if #available(iOS 12.1, *) {
let pencilInteraction = UIPencilInteraction()
pencilInteraction.delegate = self
self.addInteraction(pencilInteraction)
self.pencilInteraction = pencilInteraction
}
}

Expand All @@ -150,8 +162,10 @@ open class SwiftyDrawView: UIView {
self.backgroundColor = .clear
//Receive pencil interaction if supported
if #available(iOS 12.1, *) {
let pencilInteraction = UIPencilInteraction()
pencilInteraction.delegate = self
self.addInteraction(pencilInteraction)
self.pencilInteraction = pencilInteraction
}
}

Expand Down

0 comments on commit 3bd8dfd

Please sign in to comment.