导航控制器调整大小仅适用于纵向?

发布于 2024-11-24 14:10:04 字数 1410 浏览 1 评论 0原文

我正在开发一个在视图控制器中有导航视图控制器的应用程序。一切工作正常,除了当它不以纵向启动时,导航控制器的大小不正确并占据整个屏幕这一事实。我有截图说明发生了什么。

以下是在纵向启动应用程序时发生的情况此处

现在,当应用程序以横向右/左或纵向颠倒方式启动时,会发生这种情况 这里

我不知道是否有人有解决方案这个问题是因为它的顶部有一个空间,所以当旋转发生时总会有一个间隙。

为了获得更多参考,我添加了一些代码。

-(void)viewDidLoad{
SongsViewController *viewController = [[SongsViewController alloc] initWithNibName:@"SongsViewController" bundle:nil];

dataView = [[UINavigationController alloc] initWithRootViewController:viewController];
[dataView setDelegate:self];
dataView.view.frame = CGRectMake(192, 85, 768 - 192, 1004 - 85 - 44);
[dataView.view setAutoresizesSubviews:YES];
[dataView.view setAutoresizingMask:UIViewAutoresizingNone];

[self.view addSubview:dataView.view];
[viewController release];
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration{

if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation ==       UIInterfaceOrientationPortraitUpsideDown) {

    dataView.view.frame = CGRectMake(192, 85, 768 - 192, 1004 - 85 - 44);

}

else {

    dataView.view.frame = CGRectMake(192, 85, 1024 - 192, 748 - 85 - 44);

}

}

I am working on an app that has a navigation view controller in a view controller. Everything works fine except for the fact that when it dosen't start in portrait the navigation controller isn't properly sized and takes up the whole screen. I have screenshots how what is happening.

here is what happens when application is started in portrait here

now when the application starts in either landscape right/left or portrait upside down this happen here

I don't know if anyone has a solution for this problem since because it has a space at the top there is always a gap when the rotation occurs.

For more reference i've included some of my code.

-(void)viewDidLoad{
SongsViewController *viewController = [[SongsViewController alloc] initWithNibName:@"SongsViewController" bundle:nil];

dataView = [[UINavigationController alloc] initWithRootViewController:viewController];
[dataView setDelegate:self];
dataView.view.frame = CGRectMake(192, 85, 768 - 192, 1004 - 85 - 44);
[dataView.view setAutoresizesSubviews:YES];
[dataView.view setAutoresizingMask:UIViewAutoresizingNone];

[self.view addSubview:dataView.view];
[viewController release];
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration{

if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation ==       UIInterfaceOrientationPortraitUpsideDown) {

    dataView.view.frame = CGRectMake(192, 85, 768 - 192, 1004 - 85 - 44);

}

else {

    dataView.view.frame = CGRectMake(192, 85, 1024 - 192, 748 - 85 - 44);

}

}

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

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

发布评论

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

评论(2

离不开的别离 2024-12-01 14:10:04

首先,理想情况下,您不应该将 ViewController 的视图作为子视图添加到另一个 viewController 的视图中。至少在 iOS <= 4.3 中。

您必须做的是使用嵌入到导航控制器中的 ViewController 视图来启动您的应用程序。我的意思是,尝试将应用程序的根视图控制器设置为 navigationController。或者,如果您有一个 tabBar 作为应用程序的基础,请尝试将每个选项卡的 viewController 作为 navigationController。

接下来,使用 viewController 的属性:

self.navigationController

进一步将 viewController 推入或弹出。

您不需要在旋转委托方法中进行这些帧调整,您所要做的就是为 SongsViewController 的视图组件(子视图)正确设置自动调整大小蒙版,其余所有操作都应该自动处理。

First off, you ideally shouldnt be adding a ViewController's view as a subview to another viewController's view. Atleast in iOS <= 4.3.

What you must be doing is start your application with the ViewController's view embedded inside a navigationController. What I mean to say is, try to make the root view controller of your application as navigationController. Or, if you have a tabBar as the base of your application, try making each tab's viewController as navigationController.

Next, use the viewController's property:

self.navigationController

To further push / pop viewControllers into or from it.

You need not do those frame adjustments in the rotation delegate methods, all you have to do is set the autoresizing masks properly for the view components (subviews of) of your SongsViewController and rest all should be taken care automatically.

我一向站在原地 2024-12-01 14:10:04

使用不同的旋转函数似乎可以解决这个问题。
我用过:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration

Using a different rotation function seemed to fix the problem.
I used:

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