Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#53 Xcode 14 support #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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