ios - UIImageView shakes in UIPinchGestureRecognizer event -
i implement pinch operation ios 8.1 swift. reference next links image shakes up, down, left , right little , little.
uipinchgesturerecognizer. create zoom in location of fingers, not center
uipinchgesturerecognizer position pinched view between 2 fingers
it code in uiviewcontroller , sender.view uiimageview.
func pinchedview(sender:uipinchgesturerecognizer) { if sender.numberoftouches() < 2 { homecoming } if sender.state == uigesturerecognizerstate.began { lastscale = 1.0 lastpoint = sender.locationinview(sender.view) homecoming } allow scale = 1.0 - (lastscale - sender.scale) sender.view!.transform = cgaffinetransformscale(sender.view!.transform, scale, scale) allow newpoint = sender.locationinview(sender.view) var translation = cgpoint() translation.x = newpoint.x - lastpoint.x translation.y = newpoint.y - lastpoint.y sender.view!.transform = cgaffinetransformtranslate(sender.view!.transform, translation.x, translation.y) lastpoint = sender.locationinview(sender.view) lastscale = sender.scale }
why uiimageview shake?
instead of
sender.locationinview(sender.view)
try
sender.locationoftouch(0, inview: sender.view)
locationinview seems picking undefined touch.
ios iphone uiimageview
No comments:
Post a Comment