如何使用滑动手势访问相机?
How to access camera with swiping gesture?
我在我的 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: {})
}
}
你在哪里:
action: Selector(("handleSwipes"))
放这个:
action: #selector(handleSwipes)
原因是 "handleSwipes"
不是 您的 handleSwipes
函数的选择器,而 您 是不知道如何正确形成选择器。但是编译器确实知道,并且使用 #selector
语法告诉它这样做。
我在我的 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: {})
}
}
你在哪里:
action: Selector(("handleSwipes"))
放这个:
action: #selector(handleSwipes)
原因是 "handleSwipes"
不是 您的 handleSwipes
函数的选择器,而 您 是不知道如何正确形成选择器。但是编译器确实知道,并且使用 #selector
语法告诉它这样做。