7

I have working uicollectionview codes with CustomCollectionViewLayout , and inside have a lot of small cells but user cannot see them without zoom. Also all cells selectable.

I want to add my collection view inside zoom feature !

My clear codes under below.

class CustomCollectionViewController: UICollectionViewController {

    var items = [Item]()


    override func viewDidLoad() {
        super.viewDidLoad()


        customCollectionViewLayout.delegate = self

        getDataFromServer()

}

 func getDataFromServer() {

        HttpManager.getRequest(url, parameter: .None) { [weak self] (responseData, errorMessage) -> () in

            guard let strongSelf = self else { return }

            guard let responseData = responseData else {
                print("Get request error \(errorMessage)")
                return
            }

            guard let customCollectionViewLayout = strongSelf.collectionView?.collectionViewLayout as? CustomCollectionViewLayout  else { return }

            strongSelf.items = responseData
            customCollectionViewLayout.dataSourceDidUpdate = true

            NSOperationQueue.mainQueue().addOperationWithBlock({ () -> Void in
                strongSelf.collectionView!.reloadData()
            })
        }
    }
}

extension CustomCollectionViewController {

    override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return items.count
    }

    override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return items[section].services.count + 1
    }

    override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CustomCollectionViewCell


            cell.label.text = items[indexPath.section].base


        return cell

}

   override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath cellForItemAtIndexPath: NSIndexPath) {

     print(items[cellForItemAtIndexPath.section].base)


}

}

Also my UICollectionView layout properties under below you can see there i selected maxZoom 4 but doesnt have any action !

enter image description here

Thank you !

SwiftDeveloper
  • 7,244
  • 14
  • 56
  • 85
  • This question may be helpful : [Make collectionview zoomable](http://stackoverflow.com/questions/13485617/make-uicollectionview-zoomable) – jojoT Aug 29 '16 at 09:36
  • @jojoT ty but that sample obj-c and doing pinch zoom each item i want swift and area zoom not each item simple zoom – SwiftDeveloper Aug 29 '16 at 10:04
  • is user touches the collection view, then the cell get zoom? Do You mean, After the touch, whole collection view get blurred and touched cell only appeared center of the screen at viewable width and height? – Rajamohan S Aug 31 '16 at 06:50
  • @MohanSingh when user touch cells over will be do zoom will looks cell sizes * 6 like. simple zoom dont change cell places only will be simple zoom like photo zoom – SwiftDeveloper Aug 31 '16 at 07:57

2 Answers2

1

You don't zoom a collection like you'd zoom a simple scroll view. Instead you should add a pinch gesture (or some other zoom mechanism) and use it to change the layout so your grid displays a different number of items in the visible part of the collection. This is basically changing the number of columns and thus the item size (cell size). When you update the layout the collection can animate between the different sizes, though it's highly unlikely you want a smooth zoom, you want it to go direct from N columns to N-1 columns in a step.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • thank you but i know thats. I want to integrate my UICollectionView inside simple ZOOM when click inside will be zoom there. And I need that codes dont need ideas :) – SwiftDeveloper Aug 29 '16 at 09:19
1

I think what you're asking for looks like what is done in the WWDC1012 video entitled Advanced Collection Views and Building Custom Layouts (demo starts at 20:20) https://www.youtube.com/watch?v=8vB2TMS2uhE

You basically have to add pinchGesture to you UICollectionView, then pass the pinch properties (scale, center) to the UICollectionViewLayout (which is a subclass of UICollectionViewFlowLayout), your layout will then perform the transformations needed to zoom on the desired cell.

Evgenii
  • 422
  • 2
  • 14