Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGRect positioning according to center point

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:

enter image description here

What I did:

self.view = [[UIView alloc] initWithFrame:CGRectMake(self.parentViewController.view.frame.size.width, 0, 150, screenHeight)];

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:

enter image description here

What I'm doing (this time creating the frame on sub-menu view controller):

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);

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.

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:

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);

Yields the right position.

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?

EDIT1:

Here's the console output for the frame with right position:

enter image description here

Notice how the nav bar is now positioned right:

enter image description here

But the x-coord is not 250 (as it should be, because menu.width + sub-menu.width = 250.)

EDIT2:

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.

like image 832
diogocarmo Avatar asked Aug 12 '13 14:08

diogocarmo


People also ask

Where is the center point of the incoming geometry placed?

In the following example, the center point of the incoming geometry is placed at the center point of the host model . Use Auto - Center to Center when you are unsure of the origin points in the incoming geometry.

What is center-to-center positioning in Revit?

If the incoming geometry is a Revit link and it does not share a coordinate system with the host model, the link uses center-to-center positioning. If you are linking a DWG file, you can use this positioning option to establish shared coordinates with the Revit model.

How do I set the position of the imported geometry?

When you import or link geometry to the current Revit model, use the Positioning option of the related Import or Link dialog to specify how the incoming geometry is placed relative to the host model. Choose an option that best matches your situation and workflow.

What are the automatic positioning options?

Automatic positioning options place the incoming geometry in the host model based on a set of rules. If you know the position of coordinates in the host model and in the imported or linked file, use automatic positioning to precisely place the incoming geometry.


1 Answers

Center of a CGRect is a CGPoint created from the origin.x + ( size.width / 2 ) and origin.y + ( size.height / 2 ).

like image 89
uchuugaka Avatar answered Sep 22 '22 23:09

uchuugaka