我在我的ios應用程序中添加了滑動手勢,但不知何故,我無法訪問攝像頭。我是初學者,如果你能告訴我如何解決這個問題,我會很高興。 到目前爲止,我已經使用:如何使用滑動手勢訪問攝像頭?
import UIKit
class ViewController: UIViewController, UIImagePickerControllerDelegate,UINavigationControllerDelegate{
let imagePicker: UIImagePickerController! = UIImagePickerController()
let reachability = Reachability()!
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
self.view.backgroundColor = UIColor.flatBlackColorDark()
let upSwipe = UISwipeGestureRecognizer(target: self, action: Selector(("handleSwipes")))
upSwipe.direction = .up
view.addGestureRecognizer(upSwipe)
}
和功能:
func handleSwipes(sender:UISwipeGestureRecognizer) {
if (sender.direction == .up){
if (UIImagePickerController.isSourceTypeAvailable(.camera)){
if UIImagePickerController.availableCaptureModes(for: .rear) != nil {
imagePicker.allowsEditing = false
imagePicker.sourceType = .camera
imagePicker.cameraCaptureMode = .photo
present(imagePicker,animated: true, completion: {})
}
}
當你刷卡時會發生什麼?你調試了嗎? 'handleSwipes'甚至被稱爲? – matt
這是我得到的錯誤:終止應用程序由於未捕獲的異常'NSInvalidArgumentException',原因:' - [Audio.ViewController handleSwipes]:無法識別的選擇器發送到實例0x100d0be50' – Dakata
是的,我認爲這可能是發生了什麼! :) – matt