Ich möchte, dass mein Code einen Screenshot freigibt, wenn eine Schaltfläche namens share angeklickt wird.Activity Controller zum Teilen von Screenshots zeigt leer an
Swift 3
func shareBtnAction(_ sender: AnyObject) {
// first I take a screenshot of the drawing
UIGraphicsBeginImageContext(drawingAreaView.bounds.size)
drawingAreaView.image?.draw(in: CGRect(x: 0, y: 0, width: drawingAreaView.frame.size.width, height: drawingAreaView.frame.size.height))
// defining the variable for activityItems
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
// Initialize and present UIActivityViewController
let activity = UIActivityViewController(activityItems: [image], applicationActivities: nil)
present(activity, animated: true, completion: nil)
}
Das Ergebnis sieht jedoch wie folgt aus::
Mein Code funktioniert, wenn ich die ersetzen
Die Tastenfunktion wie folgt aussieht Bild mit einer Textzeichenfolge
func shareBtnAction(_ sender: AnyObject) {
// defining the variable for activityItems
let text = "This is a test"
// Initialize and present UIActivityViewController
let activity = UIActivityViewController(activityItems: [text], applicationActivities: nil)
present(activity, animated: true, completion: nil)
}
Also ich denke, mein Code erkennt das Bild nicht zu einem UIImage. Ich kann einfach nicht herausfinden warum.