Created
October 30, 2013 18:29
-
-
Save dblandin/7237555 to your computer and use it in GitHub Desktop.
Erica Sadun's UIView-Transform category
http://www.informit.com/articles/article.aspx?p=1951182
This file contains 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
module UIViewAdditions | |
def offsetPointToParentCoordinates(aPoint) | |
CGPointMake(aPoint.x + center.x, aPoint.y + center.y) | |
end | |
def pointInViewCenterTerms(aPoint) | |
CGPointMake(aPoint.x - center.x, aPoint.y - center.y) | |
end | |
def pointInTransformedView(aPoint) | |
offsetItem = pointInViewCenterTerms(aPoint) | |
updatedItem = CGPointApplyAffineTransform(offsetItem, transform) | |
finalItem = offsetPointToParentCoordinates(updatedItem) | |
finalItem | |
end | |
def originalFrame | |
currentTransform = transform | |
self.transform = CGAffineTransformIdentity | |
originalFrame = frame | |
self.transform = currentTransform | |
originalFrame | |
end | |
def transformedTopLeft | |
frame = originalFrame | |
point = frame.origin | |
pointInTransformedView(point) | |
end | |
def transformedTopRight | |
frame = originalFrame | |
point = frame.origin | |
point.x += frame.size.width | |
pointInTransformedView(point) | |
end | |
def transformedBottomRight | |
frame = originalFrame | |
point = frame.origin | |
point.x += frame.size.width | |
point.y += frame.size.height | |
pointInTransformedView(point) | |
end | |
def transformedBottomLeft | |
frame = originalFrame | |
point = frame.origin | |
point.y += frame.size.height | |
pointInTransformedView(point) | |
end | |
end | |
UIView.send(:include, UIViewAdditions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment