长按后选择UICollectionViewCells - Swift 3

时间:2016-11-01 00:27:09

标签: ios uicollectionview swift3 uicollectionviewcell long-press

我正在开发电子书应用程序,我有UICollectionView书籍,当用户长按UICollectionView(他需要编辑单元格),然后在顶部我显示工具(自定义"弹出"我需要添加功能,以便用户可以选择(点击)他想要删除的书籍(在每个书籍单元格中,我都有隐藏的图像(查看图标),我需要显示)。我需要一些建议,如何制作这个或者可能链接到教程。

这是我的代码(我试图在长时间按下之后将颜色改为我的细胞但是没有工作 - 如果有人可以帮助我这个):(

    @IBAction func handleGesture(_ sender: Any) {
    if (sender as AnyObject).state == UIGestureRecognizerState.began
    {
//            let alertController = UIAlertController(title: nil, message:
//                "Long-Press Gesture Detected", preferredStyle: UIAlertControllerStyle.alert)
//            alertController.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default,handler: nil))
//            
//            self.present(alertController, animated: true, completion: nil)
//



        func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell  {

            let cell = PhotoStreamView.dequeueReusableCell(withReuseIdentifier: "AnnotatedPhotoCell", for: indexPath) as! AnnotatedPhotoCell
            cell.photo = photos[(indexPath as NSIndexPath).item]
         cell.backgroundColor = UIColor.red

        return cell

        }

        // Showing Custom View as Tollbar
        let rect = CGRect(x: 0, y: 0, width: self.view.frame.width, height: 72)

        let EditBooksPopup = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "EditBooksPopup") as! EditBooksPopup
        self.addChildViewController(EditBooksPopup)
        EditBooksPopup.view.frame = rect

        self.view.addSubview(EditBooksPopup.view)
        EditBooksPopup.didMove(toParentViewController: self)


    }
}

0 个答案:

没有答案