Created
November 28, 2012 17:46
-
-
Save codeswimmer/4162822 to your computer and use it in GitHub Desktop.
iOS: Compute Position for Widget that accounts for zoom scale
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
| - (CGRect)computePositionForWidget:(UIView *)widgetView fromView:(UIScrollView *)scrollView | |
| { | |
| CGRect frame; | |
| float scale; | |
| scale = scrollView.zoomScale; | |
| // compute the widget size based on the zoom scale | |
| frame.size.width = widgetView.frame.size.width * scale; | |
| frame.size.height = widgetView.frame.size.height * scale; | |
| // compute the widget position based on the zoom scale and contentOffset | |
| frame.origin.x = widgetView.frame.origin.x * scale - scrollView.contentOffset.x + scrollView.frame.origin.x; | |
| frame.origin.y = widgetView.frame.origin.y * scale - scrollView.contentOffset.y + scrollView.frame.origin.y; | |
| // return the widget coordinates in the coordinate system of the view that contains the scroll view | |
| return( frame ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment