1
このコードでは、タイトルがネストされたカメラを備えた特別なカメラがあります。したがって、写真がフォトギャラリーに保存されると、その写真のタイトルが表示されます。カメラは素晴らしいですが、写真は保存されていません。写真をフォトギャラリーに保存する方法を理解するだけです。私は写真ギャラリーとカメラにアクセスできるようにplistを変更しました。スイフト3;写真はフォトギャラリーに保存されていません
import Foundation
import UIKit
class ViewController: UIViewController, OverlayViewControllerDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var picker = UIImagePickerController()
@IBAction func letsDoThis(_ sender: AnyObject) {
if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
picker = UIImagePickerController()
picker.allowsEditing = false
picker.sourceType = .camera
picker.cameraCaptureMode = .photo
picker.showsCameraControls = false
let overlayViewController = OverlayViewController(nibName:"OverlayView", bundle: nil)
let overlayView: OverlayView = overlayViewController.view as! OverlayView
overlayView.frame = self.picker.view.frame
overlayView.delegate = self
picker.modalPresentationStyle = .fullScreen
present(picker, animated: true, completion: {
self.picker.cameraOverlayView = overlayView
})
} else {
let alert = UIAlertController(title: "No Camera", message: "That's weird. No camera.", preferredStyle: .alert)
let okay = UIAlertAction(title: "Alright Then.", style: .default, handler: nil)
alert.addAction(okay)
present(alert, animated: true, completion: nil)
}
}
override func viewDidLoad() {
super.viewDidLoad()
picker.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
picker.dismiss(animated: true, completion: nil)
}
//MARK: Image Picker Controller Delegates
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage
UIImageWriteToSavedPhotosAlbum(chosenImage, self,nil, nil)
dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
print("Canceled!!")
}
func didCancel(overlayView: OverlayView) {
dismiss(animated: true, completion: nil)
print("dismissed!!")
}
func didShoot(overlayView: OverlayView) {
picker.takePicture()
overlayView.cameraLabel.text = "Shot Photo"
print("Shot Photo")
}
}
'UIImageWriteToSavedPhotosAlbum'への呼び出しが画像を実際に写真アルバムに保存していないと言っているようですね。 'UIImageWriteToSavedPhotosAlbum'のドキュメントを読んで、何も起こっていないことを知るために' nil'を渡している余分なパラメータを利用してください。 – rmaddy
はい、正しいです。余分な周囲長はどういう意味ですか? –
彼は 'UIImageWriteToSavedPhotosAlbum'の最後の2つのパラメータを意味します。これは' nil'に設定します。ドキュメントhttps://developer.apple.com/reference/uikit/1619125-uiimagewritetosavedphotosalbumでご覧になれます。最後の3つのパラメータはオプションです。しかし、これは私が思うあなたの問題の原因であってはならないと思います – ronatory