gpt4 book ai didi

ios - 相机没有响应

转载 作者:行者123 更新时间:2023-11-30 12:50:49 26 4
gpt4 key购买 nike

请检查我的代码,我没有任何错误,但是当我打开 View Controller 时,相机无法启动,只有黑屏,甚至按钮也没有出现。

import UIKit
import AVFoundation

class CameraViewController: UIViewController,UIImagePickerControllerDelegate,UINavigationControllerDelegate {


let picker = UIImagePickerController()
@IBOutlet weak var myImageView: UIImageView!
@IBOutlet weak var cameraView: UIView!

@IBAction func photoLibrary(_ sender: UIBarButtonItem) {

picker.allowsEditing = false
picker.sourceType = .photoLibrary
picker.mediaTypes = UIImagePickerController.availableMediaTypes(for: .photoLibrary)!
picker.modalPresentationStyle = .popover
present(picker, animated: true, completion: nil)
picker.popoverPresentationController?.barButtonItem = sender
}

@IBAction func shootPhoto(_ sender: UIBarButtonItem) {

if UIImagePickerController.isSourceTypeAvailable(.camera) {
picker.allowsEditing = false
picker.sourceType = UIImagePickerControllerSourceType.camera
picker.cameraCaptureMode = .photo
picker.modalPresentationStyle = .fullScreen
present(picker,animated: true,completion: nil)

} else {
noCamera()
}
}
func noCamera(){
let alertVC = UIAlertController(
title: "No Camera",
message: "Sorry, this device has no camera",
preferredStyle: .alert)
let okAction = UIAlertAction(
title: "OK",
style:.default,
handler: nil)
alertVC.addAction(okAction)
present(
alertVC,
animated: true,
completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
picker.delegate = self
}

//MARK: - Delegates
private func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : AnyObject])
{
var chosenImage = UIImage()
chosenImage = info[UIImagePickerControllerOriginalImage] as! UIImage //2
myImageView.contentMode = .scaleAspectFit //3
myImageView.image = chosenImage //4
dismiss(animated:true, completion: nil) //5
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}

}

我只看到完全黑屏,甚至没有来自 Swift 的提示。我现在不知道该怎么办。

最佳答案

当您尚未设置初始 View Controller 时会发生这种情况。请确保您要首先加载的 View Controller 在 Storyboard中设置为初始 View Controller 。

enter image description here

关于ios - 相机没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41002539/

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