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

发布于 2024-11-14 20:11:23 字数 243 浏览 1 评论 0原文

我正在开发一个支持横向和纵向的 iPad 应用程序。我的 rootviewController 有两个不同的 nib 文件。这是问题的场景 -
1.在纵向模式下从根视图中选择一个项目,以纵向方式推送下一个视图。
2.旋转设备
3.按导航栏上的后退按钮
从堆栈加载的视图是 rootViewController 的肖像视图。当设备仍处于横向模式时。
请提出处理上述问题的解决方案。
另外,请建议处理设备轮换时应遵循的最佳实践。

I am developing an iPad application which supports both landscape as well as portrait orientation.I am having two different nib files for my rootviewController. Here is the scenario of the issue -
1.Select an item from root view in portait mode, pushes the next view in portrait.
2.Rotate the device
3.Press back button on navigation bar
The view is loaded from the stack is portait view of rootViewController. While device is still in landscape mode.
Please suggest the solution to handle above issue.
Also, please suggest the best practices to follow while handling device rotations.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

美人如玉 2024-11-21 20:11:23

在以下方法中使用通知并在 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,这是非常重要的。

Use notifications in following methods and set the coordinates in receivedRotate method.

-(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];
}

For example in receivedRotate you can set your tableview's coordinates as :

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

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

Also call recieveRotate in viewDidLoad which is very important.

高速公鹿 2024-11-21 20:11:23

检查这个方法,可能会对你有帮助...

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

或者尝试为控制器设置 autoresizingMask 希望它会对你有所帮助。

check this method , may be help u...

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

or try to set autoresizingMask for controllers hope it will help u.

z祗昰~ 2024-11-21 20:11:23

您需要在方法运行时检查方向
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

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

You need to check orientation at runtime in method
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

}
& change elements of your view according to orientation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文