Я использую этот учебник, но у меня возникла проблема, когда в целевом целевом изображении отмены изображения, имитирующем мое приложение, которое работает только в ландшафте.Swift, камера в ландшафтном режиме
Как настроить эту камеру так, чтобы она работала только в ландшафтном режиме.
https://github.com/deege/deegeu-swift-camera-basic
https://www.dropbox.com/s/jnfwhi9s6zm30ns/Captura%20de%20pantalla%202016-05-12%2011.48.19.png?dl=0
код, вы можете загрузить проект для получения кода:
//
// ViewController.swift
// swift-camera-basic
//
// Created by Daniel Spiess on 10/16/15.
// Copyright © 2015 Daniel Spiess. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var currentImage: UIImageView!
let imagePicker: UIImagePickerController! = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
// Set this controller as the camera delegate
imagePicker.delegate = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func takePicture(sender: UIButton) {
if (UIImagePickerController.isSourceTypeAvailable(.Camera)) {
if UIImagePickerController.availableCaptureModesForCameraDevice(.Rear) != nil {
imagePicker.allowsEditing = false
imagePicker.sourceType = .Camera
imagePicker.cameraCaptureMode = .Photo
presentViewController(imagePicker, animated: true, completion: {})
} else {
postAlert("Rear camera doesn't exist", message: "Application cannot access the camera.")
}
} else {
postAlert("Camera inaccessable", message: "Application cannot access the camera.")
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
print("Got an image")
if let pickedImage:UIImage = (info[UIImagePickerControllerOriginalImage]) as? UIImage {
let selectorToCall = Selector("imageWasSavedSuccessfully:didFinishSavingWithError:context:")
UIImageWriteToSavedPhotosAlbum(pickedImage, self, selectorToCall, nil)
}
imagePicker.dismissViewControllerAnimated(true, completion: {
// Anything you want to happen when the user saves an image
})
}
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
print("User canceled image")
dismissViewControllerAnimated(true, completion: {
// Anything you want to happen when the user selects cancel
})
}
func imageWasSavedSuccessfully(image: UIImage, didFinishSavingWithError error: NSError!, context: UnsafeMutablePointer<()>){
print("Image saved")
if let theError = error {
print("An error happened while saving the image = \(theError)")
} else {
print("Displaying")
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.currentImage.image = image
})
}
}
func postAlert(title: String, message: String) {
let alert = UIAlertController(title: title, message: message,
preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
} }
пожалуйста, напишите только соответствующий код, связанный с камерой. так что можно помочь – Shubhank