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 591473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:38:17+00:00 2026-05-13T15:38:17+00:00

I have a simple screen in my iPhone app where I want a rectangle

  • 0

I have a simple screen in my iPhone app where I want a rectangle of 320×100 at the bottom of the screen to capture a touch. Here is my code inside touchesBegan:withEvent:

for (UITouch *touch in touches) {

    CGPoint touchPoint = [touch locationInView:self.view];

    NSLog(@"touch @ %f, %f", touchPoint.x, touchPoint.y);

    // build a rectangle where we want to capture a URL tap
    CGRect rectangle = CGRectMake(0, 480, 320, 100);

    NSLog(@"midX, midY = %f, %f", CGRectGetMidX(rectangle), CGRectGetMidY(rectangle));

    // check to see if they tapped the URL    
    if (CGRectContainsPoint(rectangle, touchPoint)) {
        NSLog(@"You touched inside the rectangle.");
    }        
}

Now this code does not work as intended…the log from the mid point of the rectangle shows that my rectangle is built at midX, midY = 160.000000, 530.000000. According to the CGPoint documentation, the origin (0, 480) is the lower left-hand corner, but this is acting like the origin is the upper left-hand corner.

When I change the origin of my rectangle to 0, 380, everything works as intended. Maybe I’m not properly caffeinated yet this morning, but why am I seeing this discrepancy between the documentation and the execution?

  • 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-13T15:38:18+00:00Added an answer on May 13, 2026 at 3:38 pm

    Whether the origin is in the upper-left or lower-left corner really depends on the coordinates system.

    In UIKit, the (0, 0) is in the upper-left corner, and the y-axis grows downwards.

    In CoreGraphics, the (0, 0) is in the lower-left corner, and the y-axis grows upwards. To accommodate CG to UIKit a vertical reflection is applied by default, which is why if you draw an image or string directly using the CG functions in -drawRect: you’ll get them upside-down.

    In your case, you’re getting points and rectangles from UIKit APIs, so the origin is in the upper-left corner.

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

Sidebar

Related Questions

No related questions found

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.