2016-09-28 3 views
1

shareというボタンがクリックされたときに、自分のコードでスクリーンショットを共有したい。スクリーンショットを共有するためのアクティビティコントローラが空に表示される

ボタン機能は、次のようになります。

スウィフト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) 
    } 

結果は、しかし、次のようになります。

enter image description here

私は交換するとき私のコードは動作しますテキスト文字列の画像

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) 
    } 

私のコードは画像がUIImageであると認識していないと思います。私は理由を理解できません。私は考え出し

答えて

2

、3あなたはUIImageタイプとして、より具体的にUIGraphicsGetImageFromCurrentImageContextを初期化したいSWIFT:

let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()! 
関連する問題