gpt4 book ai didi

swift - 如何使用滑动手势访问相机?

转载 作者:行者123 更新时间:2023-11-28 16:01:38 26 4
gpt4 key购买 nike

我在我的 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 语法告诉它这样做。

关于swift - 如何使用滑动手势访问相机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40964266/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com