【发布时间】:2017-04-19 06:09:24
【问题描述】:
我在我的 ios 应用程序中添加了滑动手势,但不知何故之后我无法访问相机。我是 swift 的初学者,如果你能建议我如何解决它,我会很高兴。 到目前为止我用过:
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甚至被调用了吗? -
这是我得到的错误:由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'-[Audio.ViewController handleSwipes]: unrecognized selector sent to instance 0x100d0be50'
-
是的,我认为这可能是正在发生的事情! :)