ios - Zoom a view controller in swift -
i creating ios application (swift) have multiple labels in view controller. not using scrollview. need zoom view controller on pinch gesture. know have found solutions scroll view, don't want implement scrollview in view controller. appreciated! thank you.
updated:
i have implemented scrollview in view controller. have added view in scrollview , view contains labels, issues facing are:
zoom not stay static. release fingers, scrollview automatically zoomed original was.
when view controller in original state, app crashes.
here code:
@iboutlet weak var scrollview: uiscrollview! @iboutlet var viewthis: uiview! override func viewdidload() { super.viewdidload() scrollview.delegate = self //let gesture = uipinchgesturerecognizer(target: self, action: #selector(pinchaction(sender:))) //self.view.addgesturerecognizer(gesture) // additional setup after loading view. let scrollviewframe = scrollview.frame let scalewidth = scrollviewframe.size.width / scrollview.contentsize.width let scaleheight = scrollviewframe.size.height / scrollview.contentsize.height let minscale = min(scalewidth, scaleheight); scrollview.minimumzoomscale = minscale scrollview.maximumzoomscale = 1.0 scrollview.zoomscale = minscale; } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } func viewforzooming(in scrollview: uiscrollview) -> uiview? { return viewthis }
uiview's transform
property can make view , sub views smaller or bigger, zooming effect. example working uipinchgesturerecognizer:
class exampleviewcontroller: uiviewcontroller { var previousscale:cgfloat = 1.0 override func viewdidload() { super.viewdidload() let gesture = uipinchgesturerecognizer(target: self, action: #selector(pinchaction(sender:))) self.view.addgesturerecognizer(gesture) } func pinchaction(sender:uipinchgesturerecognizer) { let scale:cgfloat = previousscale * sender.scale self.view.transform = cgaffinetransform(scalex: scale, y: scale); previousscale = sender.scale } }
and maybe need consider adjusting position of view after zooming, use cgaffinetransform(translationx: , y: )
that.
still agree uiscrollview easiest way zooming.
wiki
Comments
Post a Comment