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

  • SEARCH
  • Home
  • 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 7699409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:28:16+00:00 2026-05-31T22:28:16+00:00

I have a custom UIView that contains an interactive drawing that is drawn in

  • 0

I have a custom UIView that contains an interactive drawing that is drawn in the drawRect function of the view. On the iPad the drawing size is 1024 x 768. For the iPhone I shrink the drawing for the iPhone using CGContextScaleCTM. To keep the proper aspect ratio on my drawings I shrink the view to 480 x 360 and set the y value of the view to -20 (effectively cropping 20 pixels off the top and bottom of the View, which is fine). Everything looks correct now, but I need to convert the touch coordinates from iPhone to iPad coordinates for the interactive portions of my view to work. If I make the uiview 320 high and use

point.y *=768/320 

for converting the y value the locations are correct (but my drawing is distorted) I’ve done some tests hard coding point in so I know this should work but I’m having a hard time getting the math to work with the crop. Here is what I have so far:

CGPoint point = [[touches anyObject] locationInView:self.view];
[self endTouch:&point];
NSLog(@"true point: %@",NSStringFromCGPoint(point));
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
point.x *= 1024/480;
point.y *= 768/360;
NSLog(@"corrected point: %@",NSStringFromCGPoint(point));
}

Can anybody help me with doing this conversion? Thanks!

  • 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-05-31T22:28:18+00:00Added an answer on May 31, 2026 at 10:28 pm

    1024/480 and 768/360 perform integer division. The result of both operations is 2, but you really want 2.133333. Replace the relevant lines in your code with the following:

    point.x *= 1024.0/480.0;
    point.y *= 768.0/360.0;
    

    This will return the value you’re looking for and scale your point’s x and y values accordingly.

    You might be better served (in terms of readability) by replacing these literals with a #define macro. At the top of your code, put the following:

    #define SCALING_FACTOR_X (1024.0/480.0)
    #define SCALING_FACTOR_Y (768.0/360.0)
    

    and then modify your code to use that:

    point.x *= SCALING_FACTOR_X;
    point.y *= SCALING_FACTOR_Y;
    

    That way, it will be more clear as to what you’re actually doing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that subclasses UIView called DrawView. This class contains custom drawing
I have a simple custom UIView (a rectangle) that is implemented with drawRect. The
I have a custom UIView subclass that contains a grid of cells, each of
I have a zooming UIScrollView that contains a UIView which contains some custom UIViews
I have a UIView that gets loaded with several custom NSObjects (graphShape). Each graphShape
I have a custom UIView that draws an image in the draw rect method.
I have a UIScrollView to which I append multiple custom UIView's that contain UITextFields...
I'm drawing a custom UIView that is sitting inside a xib whose ViewController is
I've got a view controller that contains a @property which is a custom subclass
I have a custom UIView that acts as a layout object. If I add

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.