Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 手势识别器对点击没有响应_Swift_Uikit - Fatal编程技术网

Swift 手势识别器对点击没有响应

Swift 手势识别器对点击没有响应,swift,uikit,Swift,Uikit,我是新手 学习苹果公司的教程 我做任何事都是当向导的。我知道它已经过时了。 但为什么手势识别器不响应点击 我在“启用用户交互”中添加了一个复选标记 告诉我在这段代码中要修复什么,以便手势识别器对点击做出响应 //MARK: UIImagePickerControllerDelegate func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo i

我是新手 学习苹果公司的教程

我做任何事都是当向导的。我知道它已经过时了。 但为什么手势识别器不响应点击

我在“启用用户交互”中添加了一个复选标记

告诉我在这段代码中要修复什么,以便手势识别器对点击做出响应

    //MARK: UIImagePickerControllerDelegate
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        
        // The info dictionary may contain multiple representations of the image. You want to use the original.
        guard let selectedImage = info[.originalImage] as? UIImage else {
            fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
        }
        
        // Set photoImageView to display the selected image.
        photoImageView.image = selectedImage
        
        // Dismiss the picker.
        dismiss(animated: true, completion: nil)
    }

    // MARK: Actions
    
    @IBAction func selectImageFromPhotoLibrary(_ sender: UITapGestureRecognizer) {
        
        // Hide the keyboard.
        nameTextField.resignFirstResponder()
        
        // UIImagePickerController is a view controller that lets a user pick media from their photo library.
        let imagePickerController = UIImagePickerController()
        
        // Only allow photos to be picked, not taken.
        imagePickerController.sourceType = .photoLibrary
        
        // Make sure ViewController is notified when the user picks an image.
        imagePickerController.delegate = self
        present(imagePickerController, animated: true, completion: nil)
    }
    
} 

您可能没有/丢失与
@iAction
的连接。你需要再次连接它。从情节提要中找到
UIAppgestureRecognitizer
,并将控件拖动到
UIViewController
子类中,再次创建操作,在其中添加代码并删除旧方法

  • 在情节提要中找到点击手势,并控制从中拖动到
    UIViewController
  • ViewController
  • 您也可以通过编程方式来完成。以下是方法:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        tappableView.isUserInteractionEnabled = true
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(selectImageFromPhotoLibrary(_:)))
        tappableView.addGestureRecognizer(tapGesture)
    }