Last active
May 18, 2016 02:52
-
-
Save victorBaro/07c28e0a5c2cb31f4caf to your computer and use it in GitHub Desktop.
Zoom image while being pressed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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