ios - Swift: How to enable pinch-to-zoom for CALayer? -


i have been trying scroll , zoom calayer, cashapelayer, of several polygon paths. added calayer uiscrollview has enabled scrolling around calayer.

however, pinch zoom not working. several tutorials have implemented zooming uiimageview uiscrollviewdelegate so:

@iboutlet var scrollview : uiscrollview! var imageview = uiimageview() scrollview.addsubview(imageview)  func viewforzoominginscrollview(scrollview: uiscrollview) -> uiview? {     return imageview } 

but calayer incompatible uiview , have found no information on reconciling difference.

is there similar native way zoom calayer in swift? simple escaped me? appreciated; apologies if missing obvious.

after digging found related documentation apple. turns out pinch-to-zoom handled automatically on calayers if set correctly. adapted demo code swift , came basic structure, worked me.

class viewcontroller: uiviewcontroller, uiscrollviewdelegate {      @iboutlet var scrollview : uiscrollview!     var layerview = uiview()     var shapelayer= cashapelayer()      func viewforzoominginscrollview(scrollview: uiscrollview) -> uiview? {         return layerview // specify layer scroll, cannot uiscrollview used scrolling     }     func scrollviewdidendzooming(scrollview: uiscrollview, withview view: uiview!, atscale scale: cgfloat) {         // noted required no inner code necessary     }     override func viewdidload() {         super.viewdidload()         layerview.layer.addsublayer(shapelayer) // attach layer canvas view         scrollview.addsubview(layerview) // attach views         // ... add layer content, set max , min scaling values layer/view sizes encompass content     }     override func didreceivememorywarning() {         super.didreceivememorywarning()     } } 

i hope helps else!


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -