导航控制器调整大小仅适用于纵向?
我正在开发一个在视图控制器中有导航视图控制器的应用程序。一切工作正常,除了当它不以纵向启动时,导航控制器的大小不正确并占据整个屏幕这一事实。我有截图说明发生了什么。
以下是在纵向启动应用程序时发生的情况此处
现在,当应用程序以横向右/左或纵向颠倒方式启动时,会发生这种情况 这里
我不知道是否有人有解决方案这个问题是因为它的顶部有一个空间,所以当旋转发生时总会有一个间隙。
为了获得更多参考,我添加了一些代码。
-(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,理想情况下,您不应该将 ViewController 的视图作为子视图添加到另一个 viewController 的视图中。至少在 iOS <= 4.3 中。
您必须做的是使用嵌入到导航控制器中的 ViewController 视图来启动您的应用程序。我的意思是,尝试将应用程序的根视图控制器设置为 navigationController。或者,如果您有一个 tabBar 作为应用程序的基础,请尝试将每个选项卡的 viewController 作为 navigationController。
接下来,使用 viewController 的属性:
进一步将 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:
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.
使用不同的旋转函数似乎可以解决这个问题。
我用过:
Using a different rotation function seemed to fix the problem.
I used: