swift - Center collection while pinched -


i working on scrolling uicollectionview place have used pinch gesture. 2 ways i've figure out how :

the first 1 should best not work indeed.

let pinchcenter = cgpoint(x: gesture.location(in: collectionview).x - collectionview.bounds.midx,                                       y: gesture.location(in: collectionview).y - collectionview.bounds.midy)             if let index = collectionview.indexpathforitem(at: pinchcenter) {                 collectionview.scrolltoitem(at: index, at: .centeredhorizontally, animated: true)             } 

what doing, creating cgpoint placed on middle of pinch gestures (two fingers), there no indexpath in uicollectionview, not hit scrolltoitem.

second option use :

let center = gesture.location(oftouch: 1, in: collectionview) 

oftouch if point @ 1, right finger taken, if 2 left, still it's not want, not centered position of uicollectionview.

any ideas how improve precision of second option or make first working ?

edit

third option calculate point using pattern center in line :

(x1+x2/2, y1+y2/2) 

it going :

let leftpinch = gesture.location(oftouch: 1, in: collectionview)             let rightpinch = gesture.location(oftouch: 0, in: collectionview)              let avg = cgpoint(x: (leftpinch.x + rightpinch.x) / 2, y: (leftpinch.y + rightpinch.y) / 2) 

it going crash @ let leftpinch nsinternalinconsistencyexception.

thanks in advance!


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -