gpt4 book ai didi

swift - ImagePicker 确认 View 对齐

转载 作者:行者123 更新时间:2023-11-30 10:46:26 27 4
gpt4 key购买 nike

我正在使用 UIImagePickerController 来拍照。拍完照片后,我会看到一个 View 来确认拍摄或重拍。该 View 的对齐方式不同,看起来像是与屏幕底部对齐。有没有办法将两个 View 对齐到屏幕顶部,或者我可以跳过此步骤吗?

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)

最佳答案

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

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.您没有任何控件,因此您必须自己添加所有自定义;

希望这有帮助!

关于swift - ImagePicker 确认 View 对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55680789/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com