ios - 在 UICollectionView 单元内的录音按钮上显示视图
问题描述
我正在开发一个包含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
}
但这没有用,我该怎么做才能得到它?
解决方案
@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
}
}
推荐阅读
- java - Grails 默认应用程序未部署到 tomcat
- vb.net - 更改数据集访问数据库 Visual Studio
- ember.js - Ember CLI + Watchman 未检测到插件更改
- ruby-on-rails - RailsAdmin hstore 和自定义标签
- java - 过滤后如何保存ListView项索引?
- javascript - 如何在 Express Route 中捕获不定数量的参数?
- apache-camel - 如何在 apache camel 中使用 XML 安全组件实现分离的 XML 签名?
- api - 服务帐号 - 通过 API 访问
- python - 如何参数化unittest测试方法
- javascript - 文件的 URL 强制下载,如何禁用下载并将此文件存储到客户端的 javascript 变量中?