2016-09-28 2 views
1

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::

enter image description here

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.

Antwort

2

ich herausgefunden, swift 3 möchte, dass Sie UIGraphicsGetImageFromCurrentImageContext konkreter als UIImage Typ initialisieren:

let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()! 
Verwandte Themen