ImagePicker确认视图对齐

问题描述 投票:0回答:1

我正在使用UIImagePickerController来拍照。拍完照片后,我会看到确认拍摄或重拍的视图。这个视图没有以相同的方式对齐,看起来它与屏幕底部对齐。有没有办法将两个视图对齐到屏幕顶部,还是可以跳过此步骤?

Screenshot of both views

imagePickerController = UIImagePickerController()
imagePickerController.delegate = self

//check if camera is available
if UIImagePickerController.isSourceTypeAvailable(.camera) {
    imagePickerController.sourceType = .camera
} else {
    imagePickerController.sourceType = .photoLibrary
}

self.present(imagePickerController, animated: true, completion: nil)
swift uiimagepickercontroller
1个回答
0
投票

好吧,您无法使用自定义控件显示该确认屏幕。这是一个非常简单的例子:

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

  @IBOutlet weak var textField: UITextField!
  var imagePickerController: UIImagePickerController!

  override func viewDidLoad() {
    super.viewDidLoad()

    guard UIImagePickerController.isSourceTypeAvailable(.camera) else { return }
    imagePickerController = UIImagePickerController()
    imagePickerController.sourceType = .camera
    imagePickerController.showsCameraControls = false
    imagePickerController.delegate = self

    // Button to take picture
    let takePictureButton = UIButton()
    takePictureButton.setTitle("Take Picture", for: .normal)
    imagePickerController.view.addSubview(takePictureButton)

    // Positioning button
    takePictureButton.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate([
      takePictureButton.centerXAnchor.constraint(equalTo: imagePickerController.view.centerXAnchor),
      takePictureButton.bottomAnchor.constraint(equalTo: imagePickerController.view.bottomAnchor, constant: -50)
      ])

    // Set button target
    takePictureButton.addTarget(self, action: #selector(didTouchTakePictureButton(_:)), for: .touchUpInside)

    self.present(imagePickerController, animated: true, completion: nil)
  }

  @objc func didTouchTakePictureButton(_ sender: UIButton) {
    imagePickerController.takePicture()
  }

  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
    guard let image = info[.originalImage] as? UIImage else { return }
  }
}

但请注意以下事项:1。您只能使用.camera作为源类型; 2.您没有任何控制,因此您必须自己添加所有自定义;

希望这可以帮助!

© www.soinside.com 2019 - 2024. All rights reserved.