Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7904603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:09:14+00:00 2026-06-03T10:09:14+00:00

I’ve been trying to get the converted CGRect of a UIView within a UIScrollView.

  • 0

I’ve been trying to get the converted CGRect of a UIView within a UIScrollView. It works fine if I’m not zoomed, but once I zoom, the new CGRect shifts. Here is the code that’s gotten me close:

CGFloat zoomScale = (scrollView.zoomScale);    
CGRect newRect = [self.view convertRect:widgetView.frame fromView:scrollView];
CGPoint newPoint = [self.view convertPoint:widgetView.center fromView:scrollView];

//  Increase the size of the CGRect by multiplying by the zoomScale
CGSize newSize = CGSizeMake(newRect.size.width * zoomScale, newRect.size.height * zoomScale);
//  Subtract the offset of the UIScrollView for proper positioning
CGPoint newCenter = CGPointMake(newPoint.x - scrollView.contentOffset.x, newPoint.y - scrollView.contentOffset.y);

//  Create rect with the proper width/height (x and y set by center)
newRect = CGRectMake(0, 0, newSize.width, newSize.height);    

[self.view addSubview:widgetView];

widgetView.frame = newRect;
widgetView.center = newCenter;

I’m fairly certain that my issue lies in the zoomScale – I should probably be modifying the x and y coordinates based on the zoomScale value. Everything I have tried thus far has been unsuccessful, though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:09:17+00:00Added an answer on June 3, 2026 at 10:09 am

    I received the following answer from user Brian2012 on the iOS dev forums:

    What I did:

    1. Created a UIScrollView that covers the view controller’s main view.
    2. Put a desktop view (a standard UIView) in the scroll view. The origin of the desktop is at 0,0 and the size is bigger than the scroll view so I could scroll around without having to zoom first.
    3. Put some widget views (UIImageView) into the desktop view at various locations.
    4. Set the contentSize of the scroll view to the size of the desktop view.
    5. Implemented viewForZoomingInScrollView to return the desktop view as the view to scroll.
    6. Put NSLogs in scrollViewDidZoom to print out the frame of the desktop view and one of the widget views.

    What I found out:

    1. The widget frame never changes from the initial value that I set. So for example, if a widget started at position 108, 108 with a size of 64×64, then the frame is always reported as 108,108,64,64 regardless of zooming or scrolling.
    2. The desktop frame origin never changes. I put the origin of the desktop at 0,0 in the scroll view, and the origin is always reported as 0,0 regardless of zooming or scrolling.
    3. The only thing that changes is the desktop view’s frame size, and the size is just the original size multiplied by the scroll view’s zoomScale.

    Conclusion:

    To figure out the location of a widget relative to the coordinate system of the view controller’s main view, you need to do the math yourself. The convertRect method doesn’t do anything useful in this case. Here’s some code to try

    - (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 );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.