我正在尝试使用此代码使应用程序如此频繁地拍照
import UIKit
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
var cameraIsOn = false
let imagePicker = UIImagePickerController()
var timeInterval = 15
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
imagePicker.allowsEditing = false
imagePicker.sourceType = .camera
}
@IBAction func PlayButton(_ sender: UIBarButtonItem) {
present(imagePicker, animated: true) {
self.cameraIsOn = true
self.imagePicker.takePicture()
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
imageView.image = image
}
imagePicker.dismiss(animated: true) {
self.present(self.imagePicker, animated: true) {
self.cameraIsOn = true
if self.cameraIsOn {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(self.timeInterval * 60), execute: {
self.imagePicker.takePicture()
})
}
}
}
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
cameraIsOn = false
}
}
拍照后。系统会显示“重新拍摄或使用照片屏幕”。
我正在尝试以编程方式按下“使用照片”按钮,以便我可以完成循环,直到有人按下取消。
答案 0 :(得分:-1)
不确定要查找的按钮(使用照片)操作!但可以通过编程方式调用/按下UIButton。试试这个
yourButton.sendActions(用于:.touchUpInside)
让您的问题更详细会更好。您的情况是什么?您到底想实现什么目标?