Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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_Image_Return_Back - Fatal编程技术网

Swift 打开显示集合中一系列图像的第二个视图时,是否可以按集合中的图像以在第一个视图中使用图像?

Swift 打开显示集合中一系列图像的第二个视图时,是否可以按集合中的图像以在第一个视图中使用图像?,swift,image,return,back,Swift,Image,Return,Back,打开显示集合中一系列图像的第二个视图时,是否可以按集合中的图像以在第一个视图中使用图像 //从第一视图控制器 @IBAction func backgroundButton(_ sender: UIButton) { } //第二视图控制器 class SecondViewController: UIViewController { @IBAction func returnHome(_ sender: UIButton) { self.dismiss(animated: true,

打开显示集合中一系列图像的第二个视图时,是否可以按集合中的图像以在第一个视图中使用图像

//从第一视图控制器

@IBAction func backgroundButton(_ sender: UIButton) {
}
//第二视图控制器

class SecondViewController: UIViewController {

@IBAction func returnHome(_ sender: UIButton) {
    self.dismiss(animated: true, completion: nil)
}
......

extension SecondViewController: UICollectionViewDelegateFlowLayout, UICollectionViewDataSource {
        func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
            return CGSize(width: collectionView.frame.width/2.5, height: collectionView.frame.width/2)
        }
        func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
            return data.count
        }
        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
            let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! CustomCell
            cell.data = self.data[indexPath.item]
            return cell
        }
    }


class CustomCell: UICollectionViewCell {

        var data: CustomData? {
            didSet {
                guard let data = data else { return }
                bg.image = data.backgroundImage

                let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:)))
                bg.isUserInteractionEnabled = true
                bg.addGestureRecognizer(tapGestureRecognizer)

            }
        }

    @objc func imageTapped(tapGestureRecognizer: UITapGestureRecognizer) {
        let tappedImage = tapGestureRecognizer.view as! UIImageView
        self.addSubview(tappedImage)  
    }
// When I tap on Image in this case addSubview but I want use that image in First View Controller     

请修改你的代码。它在手机上几乎不可读。你是说当你在第二个视图控制器的采集视图单元格中点击图像时,你想在第一个视图控制器中使用点击的图像吗?是的,点击的图像我想将其用作第一个控制器的背景图像