Iphone UINavigationController中横向和纵向模式导航的最佳实践

Iphone UINavigationController中横向和纵向模式导航的最佳实践,iphone,ios,uinavigationcontroller,rotation,Iphone,Ios,Uinavigationcontroller,Rotation,我正在开发一个支持横向和纵向的iPad应用程序。我的rootviewController有两个不同的nib文件。以下是问题的场景- 1.在portait模式下从根视图中选择一个项目,在纵向模式下推送下一个视图。 2.旋转设备 3.按导航栏上的“后退”按钮 该视图是从rootViewController的stack is portait视图加载的。当设备仍处于横向模式时。 请提出处理上述问题的解决方案。 此外,请建议在处理设备旋转时应遵循的最佳实践。检查此方法,可能有助于您 - (BOOL)sho

我正在开发一个支持横向和纵向的iPad应用程序。我的rootviewController有两个不同的nib文件。以下是问题的场景-
1.在portait模式下从根视图中选择一个项目,在纵向模式下推送下一个视图。
2.旋转设备
3.按导航栏上的“后退”按钮
该视图是从rootViewController的stack is portait视图加载的。当设备仍处于横向模式时。
请提出处理上述问题的解决方案。

此外,请建议在处理设备旋转时应遵循的最佳实践。

检查此方法,可能有助于您

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return ( 
        interfaceOrientation == UIInterfaceOrientationPortrait 
        || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
        || interfaceOrientation == UIInterfaceOrientationLandscapeRight
        || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown
        );}

或者尝试为控制器设置autoresizingMask,希望它能帮助您。

在以下方法中使用通知,并在receivedRotate方法中设置坐标

-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

}

-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
例如,在receivedRotate中,可以将tableview的坐标设置为:

if (orientation == UIDeviceOrientationLandscapeLeft||orientation==UIDeviceOrientationLandscapeRight)
    {
        [tblView reloadData];
        tableX=70.0;

    }
    else
    {
        [tblView reloadData];
        tableX=48.0;
}  

还可以在viewDidLoad中调用recieveRotate,这非常重要。

您需要在方法中检查运行时的方向 -(布尔)应自动旋转指针面定向:(UIInterfaceOrientation)interfaceOrientation{

}
&根据方向更改视图的元素。

我将返回“是”以支持所有旋转。您能为autoresizingMask点亮一些灯吗??如何以及在何处设置它?它是UIU组件的属性。您可以将其设置为UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight。它根据方向自动调整UIcomponent的宽度和高度。感谢Amit。它与实现-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)到InterfaceOrientation持续时间:(NSTimeInterval)一起工作处理旋转的持续时间方法。感谢nitish提供的详细答案。这与上面iAmitwagh定义的类似。但我以前贴过:)