2017-06-25 5 views
0

私は私のtableViewCellに画像を持っていて、それをクリックすると(別のUIView)ポップアップが表示されます。私はポップアップに渡される画像のために私のtableviewcell上の画像をクリックしたいと思います。ポップアップを設定する方法は次のとおりです。 cellForItemAtIndexPathでtableviewcellのインデックスパスを送信

@IBAction func PopUpClicked(_ sender: Any) -> Void { 
      self.transparentBackground = UIView(frame: UIScreen.main.bounds) 
      self.transparentBackground.backgroundColor = UIColor(white: 0.0, alpha: 0.8) 
      UIApplication.shared.keyWindow!.addSubview(self.transparentBackground) 
      self.opaqueView = self.setupOpaqueView() 
      self.transparentBackground.addSubview(opaqueView) 
      UIApplication.shared.keyWindow!.bringSubview(toFront: self.transparentBackground) 
      self.view.bringSubview(toFront: transparentBackground) 

    } 

func setupOpaqueView() -> UIView{ 


     let mainView = UIView(frame: CGRect(x: 16, y: 132, width: Int(UIScreen.main.bounds.width-32), height: 403)) 
     mainView.backgroundColor = UIColor(red:0.23, green:0.73, blue:1.00, alpha:1.0) 
     mainView.layer.cornerRadius = 6 


     let OKbutton = UIButton(frame: CGRect(x: 151, y: Int(mainView.frame.height-60), width: 40, height: 40)) 
     OKbutton.setImage(UIImage.init(named: "AddOn"), for: .normal) 
     OKbutton.layer.borderColor = UIColor.white.cgColor 
     OKbutton.layer.borderWidth = 2 
     OKbutton.layer.cornerRadius = 20 



     self.imageView = UIImageView(frame: CGRect(x: 29, y: 18, width: 274, height: 310)) 
     self.imageView.layer.backgroundColor = UIColor.white.cgColor 


     mainView.addSubview(OKbutton) 
     mainView.addSubview(self.imageView) 
     OKbutton.addTarget(self, action: #selector(ThirdWheelViewController.handleOKButtonTapped(_:)), for: .touchUpInside) 

     return mainView 

    } 

    func handleOKButtonTapped(_ sender: UIButton){ 
     removeAnimate() 

    } 

    func removeAnimate() 
    { 
     UIView.animate(withDuration: 0.25, animations: { 
      self.transparentBackground.transform = CGAffineTransform(scaleX: 1.3, y: 1.3) 
      self.transparentBackground.alpha = 0.0; 

     }, completion:{(finished : Bool) in 
      if (finished) 
      { 
       self.transparentBackground.removeFromSuperview() 
      } 
     }); 
    } 
+0

カントあなたにこの保存された画像変数から読み取るself.opaqueView = self.setupOpaqueView()を使用して作成PopUpClicked機能をユーザーがクリックするだけで'self.imageView.image = cellImageView.image'を割り当てます。ここで' cellImageView'はあなたのセルの画像ビューですか? – Paulw11

答えて

0

追加し、あなたのcellForRow機能でその

let cell: CcImageGallery = collectionView.dequeueReusableCellWithReuseIdentifier("CcImageGallery", forIndexPath: indexPath) as! CcImageGallery 


    cell.btnShape.setImage(UIImage(named: shapeImg[indexPath.row] as! String), forState: .Normal) 
    cell.btnShapeText.setTitle(shapeTxt[indexPath.row] as? String, forState: .Normal) 

    cell.btnShapeRadio.addTarget(self, action: #selector(selectImage(_:)), forControlEvents: .TouchUpInside) 
    cell.btnShapeRadio.tag = indexPath.row 

    cell.btnShape.addTarget(self, action: #selector(selectImage(_:)), forControlEvents: .TouchUpInside) 
    cell.btnShape.tag = indexPath.row 

    cell.btnShapeText.addTarget(self, action: #selector(selectImage(_:)), forControlEvents: .TouchUpInside) 
    cell.btnShapeText.tag = indexPath.row 


    return cell 
+0

申し訳ありません私はすでに 'cell.PopUp.addTarget(self、action:#セレクタ(PopUpClicked)、for:UIControlEvents.touchUpInside)を持っているとは言いませんでした。 cell.PopUp.tag = indexPath.row print(indexPath.row ) cell.PopUp.isUserInteractionEnabled = true ' – juelizabeth

+0

ポップアップビューでセルをクリックしたときに画像を送信しようとしています – juelizabeth

+0

ポップアップが発生したボタンをクリックすると、残念ですが、セルIで画像を渡したいクリック – juelizabeth

0

のような項目タグ

いくつかのことでインデックスを送ること

のためにあなたの商品やタグにターゲットを追加このように画像クリックリスナー

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

次に、このよう最後

func imageTapped(tapGestureRecognizer: UITapGestureRecognizer) 
{ 
    let tappedImage = tapGestureRecognizer.view as! UIImageView 

    // Your action 
} 

にクリックされた画像を取得し、あなたは別のユーザーがボタンをクリックするまで、このイメージを望んでいません。あなたが必要とするのはイメージを渡すことではありません。イメージをメモリに保存し、ボタンをクリックするだけで済みます。だから、

var tappedImage: UIImage? 
func imageTapped(tapGestureRecognizer: UITapGestureRecognizer) 
{ 
    tappedImage = tapGestureRecognizer.view as! UIImageView 
} 

次に、このようにimageTapped関数を定義するとき、あなたのUIViewがあなたのsetupOpaqueView()機能

func setupOpaqueView() -> UIView{ 
    // methods.... 
    self.imageView = UIImageView(frame: CGRect(x: 29, y: 18, width: 274, height: 310)) 
    self.imageView.layer.backgroundColor = UIColor.white.cgColor 

    // add the stored image in this way 
    if let tappedImage = self.tappedImage { 
     self.imageView.image = tappedImage 
    } 
    // methods... 

} 
+0

申し訳ありませんが、私の質問は十分にはっきりしていないと思います。実際に送信するには、オーバーライドセグを使って情報を送信することに慣れていますが、ここではセグはありません。宛先コントローラを呼び出して情報を渡します。セグがないときに宛先コントローラを呼び出す方法がわかりません – juelizabeth

+0

@juelizabethこの 'imageTapped'関数から、どこに画像を送りますか?あなたは 'UIView'を同じビューコントローラに提示し、そのUIViewに画像を渡しますか? –

+0

それは私がやっていることです。あなたは私の質問のコードで新しいビューを呼び出すのを見ることができます – juelizabeth

関連する問題