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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:33:14+00:00 2026-05-30T03:33:14+00:00

I have a large number of views in my project where I do programmatic

  • 0

I have a large number of views in my project where I do programmatic re-sizing and re-positioning of the subviews. I do this in layoutSubviews, using code like this:

CGRect rect = self.btnOne.frame;
// change values for rect
self.btnOne.frame = rect;

// re-use same CGRect to reposition other views
rect = self.btnTwo.frame;
// change values
self.btnTwo.frame = rect;

// etc. ...

This type of code has always worked fine for me for a couple of years, now. I have recently added a bunch of code like this to a co-worker’s project, and it’s now starting to behave very strangely. For no reason I can figure out, the re-used rect object here now sometimes randomly changes its own values between when it’s assigned the frame of a view and when it is re-assigned to the view’s frame at the end of the block. The result is subviews that are in the incorrect position. It seems that the error usually takes the form of rect.origin.x somehow acquiring the value of rect.origin.y or vice versa.

Even weirder, this problem only occurs on a real device; the exact same code running on the simulator does not have the problem.

The fix is to use a uniquely-declared CGRect object for each subview, like so:

CGRect rect = self.btnOne.frame;
// change values for rect
self.btnOne.frame = rect;

// declare new CGRect to reposition other views
CGRect rect2 = self.btnTwo.frame;
// change values
self.btnTwo.frame = rect2;

When I make this change, everything goes back to working correctly. But I’m really interested in knowing why this happens, and especially knowing why it happens on a device but not on a simulator. It also seems to not happen until a co-worker makes changes to the view, although it’s not clear to me how any change (not related to positioning of views) could do this.

One other change is that the project the code was imported into is using ARC, whereas my original code was not.

  • 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-30T03:33:15+00:00Added an answer on May 30, 2026 at 3:33 am

    If there’s really nothing else going on, it sounds like a compiler error. There’s nothing magic about CGRects. They’re just structs.

    Do you get the same results with and without optimizations? On different compilers (gcc-llvm vs clang, gcc if you still have it)?

    Is this all on armv7 devices? There are known issues with thumb code on armv6 devices and in the past it hasn’t been disabled. As of Xcode 4.3, Apple seems to want to turn off thumb for all archs.

    If the code is as simple as you show, it shouldn’t be that hard to look at the assembly.

    I reuse CGRects all the time.

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

Sidebar

Related Questions

I have a large number of csv files that look like this below: xxxxxxxx
I have a large number of instances of a C structure like this: struct
We have a fairly large MVC project with a large number of views and
I have a very large script which is creating multiple views. In a number
We have a large number of programmers on different platforms all using CVS. We
I have an Xcode project with a large number of targets where I would
I have a large number of custom views (all the same class) in a
We have developed a large number of websites using ASP (jscript flavour), talking to
I am using the WMD markdown editor in a project for a large number
I have a large number of records (10,000, increasing every day) that essentially is

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.