views:

371

answers:

3

iPad Gurus: Apple wants us to support all orientations. I take that to mean that a particular layout should either rotate so that all objects are positioned relatively the same OR, if that doesn't look good, then they ought to be repositioned, OR two views ought to be designed and built.

If I rely on the built-in rotation mechanism, the objects either get resized or they straddle the edge of the page in one orientation or the other, or they disappear from view altogether. I can't seem to find the right settings to get the objects to align clearly so they are seen in each orientation.

Repositioning leads to a lot of if statements in the View Controller. So I don't think Apple had that in mind.

I tried replacing views and even view controllers in "willRotateToInterfaceOrientation" method, but that either causes crashes or the portrait views end up in landscape unexpectedly and vv. Moreover, two view controllers means double the coding for the same view.

There must be proper way to handle orientation changes, but I have searched the internet and documentation and sample code in vain for something that works. How is this done properly?

Thanks!

A: 

Spend some time in Interface Builder getting to understand what "autosizing" and "size & position" do (size inspector). They can be configured separately for each UILabel, Button, Bar, Image etc.

Also scale to fill, aspect fit, aspect fill etc. are useful to understand (attributes inspector).

Don't forget to override shouldAutorotateToInterfaceOrientation to return YES and then everything should work using a single UIViewController and UIView.

Tarmo
A: 

Thanks to the great post at OranLooney.com I was able to get a java/icefaces web-app to resize nicely on the ipad.

the donnothing(); in the window.orientationchange is there as it seems sometimes without it the resize will (sometimes) not work, in your case though i imagine this is where you want to put the code to launch a new view.

// a function to parse the user agent string; useful for 
// detecting lots of browsers, not just the iPad.
function checkUserAgent(vs) {
    var pattern = new RegExp(vs, 'i');
    return !!pattern.test(navigator.userAgent);
}
if ( checkUserAgent('iPad') ) {
    // iPad specific stuff here
 window.onorientationchange = function() {
  donnothing();
 };
}

also if you figure out how to allow double click let us know !!

Luke
return !!patte... - since ! is negation, what is the purpose of !! which results in the original statement then?
Mikulas Dite
A: 

Yes yes my iPad game was rejected because I did not support all views. I hope I save some one a week of waiting to get rejected.

Chris