【发布时间】:2020-05-15 21:51:58
【问题描述】:
我正在开发一个包含 collectionview 的 iOS 应用程序,在这个 collectionview 中我有一个按钮,如下所示:
ViewController
-UICollectionView(myColl)
--UICollectionViewCell
---UIButton (myButton)
-UIView (myView)
我想要做的是当我点击它时在myButton下显示myView,我尝试的是:
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
}
但这没有用,我该怎么做才能得到它?
【问题讨论】:
-
澄清一下,
myView包含在您的UICollectionViewCell中,并且在选择时您希望视图显示在所选单元格的后面?如果您也滚动,myView是否应该留在您的UICollectionViewCell后面?还是只是选择? -
不,它不是 UICollectionViewCell,我希望它只出现在选择中,并在滚动时隐藏。
标签: ios swift uicollectionview uibutton uicollectionviewcell