Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MythicFrost

macrumors 68040
Original poster
Mar 11, 2009
3,944
40
Australia
OK, in Visual Basic I'd simply add the buttons labels and what not to a Picture Box or some form of group object, that way I center the picture box in the middle of the window, and the content is centered because it's in the (invisible) picture box.

Is there some kind of thing like that that I can use?
Currently I'm doing:
Code:
[bButton setCenter:(CGPointMake(iWidth/2, (iHeight/2)))];
But if I have multiple objects I have to calculate the distance and height of each object and adjust the Y position of each one to get them to be exactly centered, I'd like some kind of control I can add them to.

Any idea's? Thanks.
 
Alright I've done that, but it is for dealing with the orientation of the device right?
All I want to do is find an easy way to quickly position controls, rather than calculating it all in my head.

I've set
Code:
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth & UIViewAutoresizingFlexibleHeight;

What would I do to force the orientation of the device to sideways? that's the way my app is intended to be held anyway.

Thanks
 
but it is for dealing with the orientation of the device right?

The autoresizingMask deals with positioning a view relative to its superview. When the orientation changes the view will be re-positioned automatically based on the autoresizingMask.

However, if you're asking: "can I just throw a view out there and get it to be automatically positioned" I think the answer is no. It needs an initial position.

Of course if you lay your UI out in IB then this isn't really a problem.
 
I think I'm doing ok doing it via maths, but I'm interested in getting my view to change when it rotates. Just out of curiosity.

I've got my button in the very center of the screen, when I flip the device to the left though, it doesn't rotate around it's center. Do you know how I could get that result?

Thanks
 
Depends on exactly what you mean by flip around its center.

Using an autoresizingMask of flexible width and height the view will be adjusted when its parent is resized due to rotation. You need all the containing views in the view hierarchy to do this. Typically there is one container view that is the view controller's view property and then you add your controls to that view. Make sure that the container view has its autoresizingMask set.
 
In MyGameViewController.m in viewDidLoad() I create all my controls, and I add them to the view by [[self view] addSubview:()];

When I rotate the device, nothing happens.
 
Did you implement shouldAutorotateToInterfaceOrientation: and return YES?

If you did that already what do you mean by nothing happens? Does anything appear rotated?
 
No I didn't implement that, how do I do that?
EDIT: I've done this:
Code:
[self shouldAutorotateToInterfaceOrientation:(YES)];
Nothing rotates, it looks correct if the device has the home button at the bottom, but if I turn it to the left it looks wrong, no rotating.
EDIT: Image attached.
 

Attachments

  • Screen shot 2009-12-22 at 10.33.00 AM.png
    Screen shot 2009-12-22 at 10.33.00 AM.png
    54.7 KB · Views: 91
That's not it.

In your view controller add this code:

Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations
	return YES;
}

You do have a view controller don't you?

Subclasses of UIViewController must or may implement various methods that are called by the system. This particular one reports to the system what orientations the view controller supports.
 
Normally when you create a project from a template it creates a view controller and it has this method in it. The stock version of this method works only in portrait orientation. Like this:

Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
	// Return YES for supported orientations
	return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

You should be able to make that work with landscape instead.

FWIW, apps that only work in landscape are a bit of a pain to set up. Is that your goal?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.