在UICollectionView单元内的录音按钮上显示视图

问题描述 投票:0回答:2

我正在使用一个包含collectionview的iOS应用,在此collectionview中,我有一个按钮,如下所示:

ViewController
-UICollectionView(myColl)
--UICollectionViewCell
---UIButton (myButton)
-UIView (myView)

我想做的是点击myView时显示myButton,我尝试的是:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
   let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TestCell", 
          for: indexPath) as! TestCell
   cell.myButton.addTarget(self, action: #selector(self.showEditView), for: .touchUpInside)
}

以及showEditView()中的>

@objc func showEditView(sender:UIButton!)  {
        let position: CGPoint = sender.convert(CGPoint.zero, to: self.myColl)
        myView.center = position
}

但是那没用,我该怎么办?

我正在使用一个包含collectionview的iOS应用程序,在这个collectionview中,我有一个按钮,如下所示:ViewController -UICollectionView(myColl)--UICollectionViewCell --- UIButton(myButton)...

ios swift uicollectionview uibutton uicollectionviewcell
2个回答
1
投票
@objc func showEditView(sender:UIButton!) { let position: CGPoint = sender.convert(CGPoint.zero, to: self.collectionview) let indexPath = self.collectionview.indexPathForItem(at: position) if indexPath != nil { myView.center = position //if your view is hidden myView.isHidden = false } }

0
投票
实际上,您可以在UICollectionViewCell中使用协议。比使用伪造更健康。
© www.soinside.com 2019 - 2024. All rights reserved.