How to access camera with swiping gesture?

落爺英雄遲暮 提交于 2019-12-23 05:16:01

问题


I have added a swipe gesture in my ios application, but somehow I can't access the camera afterward. I am beginner in swift and I would be very glad if you can advice me how to fix it. So far I have used:

  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)

}

and for the function:

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: {})
                }
            }

回答1:


Where you have:

action: Selector(("handleSwipes"))

put this:

action: #selector(handleSwipes)

The reason is that "handleSwipes" is not the selector for your handleSwipes function, and you do not know how to form the selector correctly. But the compiler does know, and using #selector syntax tells it to do so.



来源:https://stackoverflow.com/questions/40964266/how-to-access-camera-with-swiping-gesture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!