Skip to content

Instantly share code, notes, and snippets.

@victorBaro
Last active May 18, 2016 02:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorBaro/07c28e0a5c2cb31f4caf to your computer and use it in GitHub Desktop.
Save victorBaro/07c28e0a5c2cb31f4caf to your computer and use it in GitHub Desktop.
Zoom image while being pressed
func imagePressed(sender: ForceGestureRecognizer) {
let point = sender.locationInView(self.view)
let imageCoordPoint = CGPointMake(point.x - initialFrame.origin.x, point.y - initialFrame.origin.y)
var xValue = max(0, imageCoordPoint.x / initialFrame.size.width)
var yValue = max(0, imageCoordPoint.y / initialFrame.size.height)
xValue = min(xValue, 1)
yValue = min(yValue, 1)
let anchor = CGPointMake(xValue, yValue)
mainImageView.layer.anchorPoint = anchor
let forceValue = max(1, sender.forceValue)
mainImageView.layer.transform = CATransform3DMakeScale(forceValue, forceValue, 1)
if sender.state == .Ended {
mainImageView.layer.anchorPoint = CGPointMake(0.5, 0.5)
mainImageView.layer.transform = CATransform3DIdentity
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment