facebook twitter hatena line email

「Ios/swift/画像保存」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==画像保存== UIImageWriteToSavedPhotosAlbum(_imageView.image!, self, #selector(ImageDetailViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)...」)
 
 
行1: 行1:
 
==画像保存==
 
==画像保存==
    UIImageWriteToSavedPhotosAlbum(_imageView.image!, self, #selector(ImageDetailViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)
+
        let ac = UIAlertController(title: "画像保存", message: "この画像を保存しますか?", preferredStyle: .Alert)
   
+
        let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) -> Void in}
 +
        let okAction = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in
 +
            UIImageWriteToSavedPhotosAlbum(self._imageView.image!, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil)
 +
        }
 +
        ac.addAction(cancelAction)
 +
        ac.addAction(okAction)
 +
        presentViewController(ac, animated: true, completion: nil)
 +
 
 
     func image(image: UIImage, didFinishSavingWithError error: NSError!, contextInfo: UnsafeMutablePointer<Void>) {
 
     func image(image: UIImage, didFinishSavingWithError error: NSError!, contextInfo: UnsafeMutablePointer<Void>) {
 
         var title:String = "保存完了"
 
         var title:String = "保存完了"

2016年8月1日 (月) 10:05時点における最新版

画像保存

       let ac = UIAlertController(title: "画像保存", message: "この画像を保存しますか?", preferredStyle: .Alert)
       let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { (action) -> Void in}
       let okAction = UIAlertAction(title: "OK", style: .Default) { (action) -> Void in
           UIImageWriteToSavedPhotosAlbum(self._imageView.image!, self, #selector(self.image(_:didFinishSavingWithError:contextInfo:)), nil)
       }
       ac.addAction(cancelAction)
       ac.addAction(okAction)
       presentViewController(ac, animated: true, completion: nil)
   func image(image: UIImage, didFinishSavingWithError error: NSError!, contextInfo: UnsafeMutablePointer<Void>) {
       var title:String = "保存完了"
       var message:String = "アルバムへの保存完了"
       if error != nil {
           title = "エラー"
           message = "アルバムへの保存に失敗しました"
       }
       let alert:UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
       alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: {
           (action) -> Void in
           print("ok")
       }))
       self.presentViewController(alert, animated: true, completion: {})
   }

参考:http://swift-studying.com/blog/swift/?p=473