Strategies for Orientation/Repositioning

H

haarlequin

Guest
With the code working, it's time to get the interface looking nice in all orientations.

Does anyone have any general advice about which way to go - and which ways not to go?

I'm assuming at the moment that I'm best putting groups of elements into views and that those views then have methods to reposition themselves when rotated? Or do superviews reposition their subviews?

Thanks.
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
You can reposition all of your views and sub views with code, but you have to provide all of
the CGPoints and X and Y coordinates for the different orientations, so the easiest way is to
let the iOS systems autorotation method handle things for you.

And yes, the super view will automatically rotate its sub views, in the autorotation method
provided.

I recently posted the correct implementation of this method in another forum post, but I have
posted it again below.

Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)io
{
    return (io == UIInterfaceOrientationPortrait || UIInterfaceOrientationIsLandscape(io);
}

The above code should be in the super view's controller class, and this implementation of
the method, will allow for any portrait, or landscape orientation, but you can change this
methods code to only support certain orientations if you wanted.

You did'nt say wether you where coding for the iPhone or iPad, as you should also be
aware, that there are some types of view controller that are device specific, for example the
UISplitViewController class, will only operate on the iPad, so check the documentation to
see if the type of view controller class's you are using, are universal to both devices.

Hope this is of some help.

Regards Mark
 
OP
H

haarlequin

Guest
Thanks Mark. I'm okay with the orientation itself (so far, anyway) but I'm looking for a sensible way to reposition the control elements - recentering being the most frequent need. This applies to both iPad and iPhone of course.

Is there some kind of

[myButton whereAmIinTheWindow]

or

[myButton.super whereIsMyButtonInTheWindow]

call I can make?
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
The UIButton class is a sub class of UIView, so any methods or properties of UIView can
be called on a UIButton, that includes all of the CGPoint CGRect and Bounds properties, I
believe from memory that the UIView class has frame and center properties, which gets
and sets the view's position within its super view.

So those UIView properties and methods are the nearest thing to a where am i
implementation for a UIButton object.

So read the docs on the UIView class, and you can use any of the methods on all of the
other UI controls.

Regards Mark
 
OP
H

haarlequin

Guest
Ah, that sounds like what I'm looking for. I'll bury my head in that as soon as I can.
Thanks.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top