my App has several uiViews and set to support both orientations. since my uiViews frames are only part of the whole size of the iPad, so I’m trying to center my uiviews frame depending on how the iPad is held aka orientation. It’s is done in this manner in the view controller.m file:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
UIInterfaceOrientation des=self.interfaceOrientation;
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) //iPad
{
CGRect ScreenBounds = [[UIScreen mainScreen] bounds];
if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown)//ipad-portrait
{
ipStPosX=(ScreenBounds.size.width -360)/2;
ipStPosY=100;
return YES;
}
else//ipad -landscape
{
ipStPosX=(ScreenBounds.size.height -360)/2;
ipStPosY=100;
return YES;
}
}
else//iphone
{
UIInterfaceOrientation des=self.interfaceOrientation;
if(des==UIInterfaceOrientationPortrait||des==UIInterfaceOrientationPortraitUpsideDown) //iphone portrait
{
return NO;
}
else //iphone -landscape
{
return YES;
}
}
}
after launching the app and changing the orientation it will always go to the portrait part, UIInterfaceOrientationPortrait, regardless of how i hold the device.
I saw some old posts that didn’t really fit the issue and were confusing or dated so any help here will be great.
shouldAutorotateToInterfaceOrientation:is for simply telling iOS that you support particular orientations. since you want everything but iPhone landscape, you should returnfor actually adjusting what you display, you want to use
willRotateToInterfaceOrientation:duration:ordidRotateFromInterfaceOrientation:for actually changing items. in your case, given that you are just adjusting some iVars depending upon which orientation you are in, i presume you will use the latter.