我使用下面的代码让用户从他们的照片库中选择一张图片。 它适用于iPhone,但在iPad上,用户界面看起来与iPhone上的相同。不应该有所不同吗?我如何让它看起来像这样...... Image Link
这是我的代码......
import UIKit
class PostExperienceViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var ImageView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func segmentedControll(sender: UISegmentedControl) {
let segmentedControl = sender as UISegmentedControl
switch segmentedControl.selectedSegmentIndex {
case 0:
//photo library
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) {
let imagePicker:UIImagePickerController = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
case 1:
//camera
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera) {
let imagePicker:UIImagePickerController = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
imagePicker.allowsEditing = false
self.presentViewController(imagePicker, animated: true, completion: nil)
}
default:
break;
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {
self.dismissViewControllerAnimated(true, completion: nil)
self.ImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
}
答案 0 :(得分:1)
我自己找到了答案......
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary) {
let imagePicker:UIImagePickerController = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
imagePicker.allowsEditing = false
if UIDevice.currentDevice().userInterfaceIdiom == .Phone {
self.presentViewController(imagePicker, animated: true, completion: nil)
}
else {
imagePicker.modalPresentationStyle = .Popover
presentViewController(imagePicker, animated: true, completion: nil)//4
imagePicker.popoverPresentationController?.sourceView = (sender as UISegmentedControl)
imagePicker.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.Up
imagePicker.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0)
}
}