title: CGRect positioning according to center point
body: <p>I'm trying to create multiple views for an iPad app. First I created a menu view and then a sub-menu view with coordinates according to menu. So it looks like this:</p>
  
  <p><img src="https://i.stack.imgur.com/Lvb7e.png" alt="enter image description here"></p>
  
  <p>What I did:</p>
  
  <pre><code>self.view = [[UIView alloc] initWithFrame:CGRectMake(self.parentViewController.view.frame.size.width, 0, 150, screenHeight)];
  </code></pre>
  
  <p>But now on sub-menu I'm trying to create the content view, which is a UINavigationController. Trying to do the same thing, I get this result:</p>
  
  <p><img src="https://i.stack.imgur.com/fNVjk.png" alt="enter image description here"></p>
  
  <p>What I'm doing (this time creating the frame on sub-menu view controller):</p>
  
  <pre><code>CGRect frame = CGRectMake(self.view.frame.origin.x + self.view.frame.size.width,
                              0,
                              [[UIScreen mainScreen] bounds].size.width - self.view.frame.origin.x - self.view.frame.size.width,
                              [[UIScreen mainScreen] bounds].size.height);
  </code></pre>
  
  <p>It's pretty self-explanatory but, I just get the sub-menu origin and add its width so I can get the right edge coordinate.</p>
  
  <p>After a lot of attempts I managed to get it working, because I noticed that the CGRectMake is using the center of the UINavigationController view to arrange its position. So the following code:</p>
  
  <pre><code>CGRect frame = CGRectMake(self.view.frame.origin.x + self.view.frame.size.width + 259,
                              0,
                              [[UIScreen mainScreen] bounds].size.width - self.view.frame.origin.x - self.view.frame.size.width,
                              [[UIScreen mainScreen] bounds].size.height);
  </code></pre>
  
  <p>Yields the right position.</p>
  
  <p>What's going on? I thought CGRectMake origin would always be top-left, but on this particularly view is actually top-middle (or middle-middle, not sure.) What am I doing wrong?</p>
  
  <p><strong>EDIT1:</strong></p>
  
  <p>Here's the console output for the frame with right position:</p>
  
  <p><img src="https://i.stack.imgur.com/JIQQR.png" alt="enter image description here"></p>
  
  <p>Notice how the nav bar is now positioned right:</p>
  
  <p><img src="https://i.stack.imgur.com/C8mWZ.png" alt="enter image description here"></p>
  
  <p>But the x-coord is not 250 (as it should be, because menu.width + sub-menu.width = 250.)</p>
  
  <p><strong>EDIT2:</strong></p>
  
  <p>I eventually gave up. The problem was with the automatically generated UINavigationBar, which is created by the UINavigationViewController. I can't seem to figure out how to configure it. I'm gonna leave the question open in case someone knows the answer.</p>