1

i have a collection view cell having an image view in it. i want to have a scenario where on double clicking the image opens it on a full image view and again double clicking removes that full image from that image view.

 var a = ["1.png","2.png"]

    override func viewDidLoad() {
        super.viewDidLoad()

        collectionView!.dataSource = self
        collectionView!.delegate = self
        collectionView!.registerClass(CollectionViewCell.self, forCellWithReuseIdentifier: "CollectionViewCell")
        collectionView!.backgroundColor = UIColor.whiteColor()
        self.view.addSubview(collectionView!)


        var gestureRecognizer: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "tapImageView:")
        self.imageview.addGestureRecognizer(gestureRecognizer)
        gestureRecognizer.numberOfTapsRequired = 1



    }

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        var cell = collectionView.cellForItemAtIndexPath(indexPath) as CollectionViewCell
        if((cell.selected) && (indexPath.row%2 == 0))
        {
//            cell.imageView?.image = UIImage( named: a[indexPath.row])
            cell.backgroundColor = UIColor.greenColor()
         //  imageview.image = UIImage( named: a[indexPath.row])
            btn_close.hidden = false
            let aSelector : Selector = "start:"
            let tapGesture = UITapGestureRecognizer(target: self, action: aSelector)
            let tap1 = UIGestureRecognizer(target: self, action: aSelector)
            tapGesture.numberOfTapsRequired = 2
            cell.addGestureRecognizer(tapGesture)


//            var gestureRecognizer: UITapGestureRecognizer = UITapGestureRecognizer(target: self, action: "tapImageView:")
//            self.imageview.addGestureRecognizer(gestureRecognizer)
//            gestureRecognizer.numberOfTapsRequired = 2


        }
        else if((cell.selected) && (indexPath.row%2 != 0))
        {
            cell.backgroundColor = UIColor.redColor()
         //  imageview.image = UIImage( named: a[indexPath.row])
            btn_close.hidden = false

        }
    }

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
        var abc : CGSize!

        if(a.count == 1){
            abc = CGSize(width: self.view.frame.width, height: self.view.frame.height/2)
        }
        else if(a.count == 2) {
            abc = CGSize(width: self.view.frame.width/2, height: self.view.frame.height/2)
        }
        else if (a.count == 3) || (a.count==5){
            abc = CGSize(width: self.view.frame.width/3, height: self.view.frame.height/2)
        }
        else if(a.count == 4) {
            abc = CGSize(width: self.view.frame.width/2, height: self.view.frame.height/5)
        }
        else if (a.count>=5) && (a.count<9){
            abc = CGSize(width: self.view.frame.width/3.05, height: self.view.frame.height/4.75)
        }
        else if (a.count>=9){
            abc = CGSize(width: self.view.frame.width/3, height: self.view.frame.height/9)
        }
             return abc
    }
  • the above posted code is what i have right now. i am actually unable to use double tap gesture – SameerVerma Sep 29 '15 at 12:08
  • Adding the GR at `didSelectItem:` does not make sense. You can follow the principles described in [Long press gesture on UICollectionViewCell](http://stackoverflow.com/questions/18848725/long-press-gesture-on-uicollectionviewcell) and add your gesture recogniser to the `UICollectionView` itself – spassas Sep 29 '15 at 13:06
  • can you post something that is written in swift.? spassas – SameerVerma Sep 29 '15 at 13:13

0 Answers0