Created
October 24, 2018 00:21
-
-
Save derickito/d78a8b53493035e86e977c17ea381eb9 to your computer and use it in GitHub Desktop.
Function to find the annotations that intersect with an array of selections using Apple's PDFKit in iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func annotationsIn(selections: [PDFSelection]) -> [PDFAnnotation] { | |
if selections.count == 0 { return [] } | |
var results: [PDFAnnotation] = [] | |
for selection in selections { | |
//See if rect matches the annotations in this page | |
let page = selection.pages.first! | |
let bounds = selection.bounds(for: page) | |
for annotation in page.annotations { | |
if bounds.intersects(annotation.bounds) { | |
results.append(annotation) | |
} | |
} | |
} | |
return results | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment