Skip to content

Instantly share code, notes, and snippets.

@codeswimmer
Created November 28, 2012 17:46
Show Gist options
  • Select an option

  • Save codeswimmer/4162822 to your computer and use it in GitHub Desktop.

Select an option

Save codeswimmer/4162822 to your computer and use it in GitHub Desktop.
iOS: Compute Position for Widget that accounts for zoom scale
- (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