How can I detect device orientation going back and forth through tabs and views?
My application goes back and forth between Portrait and Landscape. I have all of my content(labels, uiimageviews, uilabels) lined up to relocate for both orientations. However, the only change when the device is actually rotated. When I cycle between tabs after it has been rotated it just shows up autosized and not the way I have it setup when the user rotates it.
How can I detect the orientation of the device and display the view to reflect the orientation when the taps different tabs?
Ok, I set it to viewWillAppear. Is there a reason why it isn't detecting the orientation and displaying the content where I have set it?
-(void)vi开发者_高级运维ewWillAppear:(UIInterfaceOrientation)fromInterfaceOrientation duration:(NSTimeInterval)duration{
UIInterfaceOrientation toOrientation = self.interfaceOrientation;
[UIView beginAnimations:@"move buttons" context:nil];
[UIView setAnimationDuration:0.5f];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if(toOrientation == UIInterfaceOrientationPortrait
|| toOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
aboutContent.frame = CGRectMake(20, 100, 280, 107);
myLogo.frame = CGRectMake(-5, 20, 330, 65);
bulletOne.frame = CGRectMake(40, 220, 240, 45);
bulletTwo.frame = CGRectMake(40, 270, 240, 45);
}
else
{
aboutContent.frame = CGRectMake(40, 80, 400, 70);
myLogo.frame = CGRectMake(230, 30, 20, 20);
bulletOne.frame = CGRectMake(90, 140, 330, 65);
bulletTwo.frame = CGRectMake(90, 170, 330, 65);
}
[UIView commitAnimations];
}
In each UIViewController's viewWillAppear check the device's orientation and if the orientation is different from how you have it layed out then send willRotateToInterfaceOrientation:duration: to self. That's assuming that your willRotateToInterfaceOrientation:duration: will update the layout to the specified orientation.
精彩评论