导航栏出现在带有新 iOS7 SDK 的视图上 [英] Navigation bar appear over the views with new iOS7 SDK

查看:18
本文介绍了导航栏出现在带有新 iOS7 SDK 的视图上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CGRect cgRect1 = [[UIScreen mainScreen] applicationFrame];UISearchBar *mySearchBar = [[UISearchBar 分配]initWithFrame:CGRectMake(0, 0, cgRect.size.width, 40)];mySearchBar.autoresizingMask =UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight ;UITableView *myTableView = [[UITableView 分配]initWithFrame:CGRectMake(0, 40, cgRect.size.width, cgRect.size.height-40)];myTableView.autoresizingMask =UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;[self.view addSubview:mySearchBar];[self.view addSubview:myTableView];

在早期版本中它可以正常工作.搜索栏出现在 statusbar 和导航栏下方.tableview 出现在搜索栏下方

但是当我在 Xcode 5 sdk iOS 7 上运行它时,搜索栏不可见(我认为它位于状态栏和导航栏下方),并且导航栏也出现了表视图.

iOS 7 稳定版会修复吗?

还是我编码的问题?

或者我们应该通过为 iOS 7 添加 y (y = statubar height + nav bar height) 值来处理它?<​​/p>

我最近下载了 Xcode 5 DP 以在 iOS 7 中测试我的应用程序.我注意到并确认的第一件事是我的视图边界并不总是调整大小以适应状态栏和导航栏.

在 viewDidLayoutSubviews 中,我打印视图的边界:

{{0, 0}, {320, 568}}

这会导致我的内容出现在导航栏和状态栏下方.

我知道我可以通过获取主屏幕的高度、减去状态栏的高度和导航栏的高度来自己计算高度,但这似乎是不必要的额外工作.

有其他人遇到过这个问题吗?

更新:

我找到了解决这个特定问题的方法.将导航栏的半透明属性设置为 NO:

self.navigationController.navigationBar.translucent = NO;

这将修复导航栏和状态栏下方的视图.

但是,当您希望导航栏半透明时,我还没有找到解决方法.例如,在全屏查看照片时,我希望导航栏是半透明的,并且视图在其下方被框起来.这有效,但是当我切换显示/隐藏导航栏时,我遇到了更奇怪的结果.第一个子视图(UIScrollView)每次都改变它的边界和原点.

解决方案

这并不完全正确.iOS 7 中引入了一个新属性,可让您像在以前的 iOS 版本中一样调整布局行为.把这段代码放在你的视图控制器中,你应该很高兴!导航栏占用的空间应自动计算

 if ([self RespondsToSelector:@selector(edgesForExtendedLayout)])self.edgesForExtendedLayout = UIRectEdgeNone;

您需要在 -(void)viewDidLoad 方法中添加上述内容.

注意:您现在应该使用最新的 GM 版本的 iOS 7 和 Xcode 5,因为 API 已从测试版更改.

CGRect cgRect1 = [[UIScreen mainScreen] applicationFrame];


UISearchBar  *mySearchBar = [[UISearchBar alloc] 
               initWithFrame:CGRectMake(0, 0, cgRect.size.width, 40)];

mySearchBar.autoresizingMask = 
              UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight ;


UITableView  *myTableView = [[UITableView alloc] 
     initWithFrame:CGRectMake(0, 40, cgRect.size.width, cgRect.size.height-40)];

myTableView.autoresizingMask = 
               UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;


[self.view addSubview:mySearchBar];
[self.view addSubview:myTableView];

In the earlier versions it is working correctly. The search bar is appearing below the statusbar and navigation bar. The tableview is appearing below the search bar

But when I run this on Xcode 5 sdk iOS 7, the search bar is not visible (I think its placed under the status bar and navigation bar) , and also the navigation bar is appearing over the table view.

Will it be fixed with iOS 7 stable release ?

Or is it the problem of my coding ?

Or should we handle it by adding the y (y = statubar height + nav bar height) value for iOS 7 ?

I recently downloaded Xcode 5 DP to test my apps in iOS 7. The first thing I noticed and confirmed is that my view's bounds is not always resized to account for the status bar and navigation bar.

In viewDidLayoutSubviews, I print the view's bounds:

{{0, 0}, {320, 568}}

This results in my content appearing below the navigation bar and status bar.

I know I could account for the height myself by getting the main screen's height, subtracting the status bar's height and navigation bar's height, but that seems like unnecessary extra work.

Has anyone else experienced this issue?

UPDATE:

I've found a solution for this specific problem. Set the navigation bar's translucent property to NO:

self.navigationController.navigationBar.translucent = NO;

This will fix the view from being framed underneath the navigation bar and status bar.

However, I have not found a fix for the case when you want the navigation bar to be translucent. For instance, viewing a photo full screen, I wish to have the navigation bar translucent, and the view to be framed underneath it. That works, but when I toggle showing/hiding the navigation bar, I've experienced even stranger results. The first subview (a UIScrollView) gets its bounds y origin changed every time.

解决方案

That’s not entirely true. There has been a new property introduced in iOS 7 that lets you adjust the layout behavior as in previous versions of iOS. Place this piece of code in your view controller, and you should be good to go! The space your navigation bar takes up should be accounted for automatically

 if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
    self.edgesForExtendedLayout = UIRectEdgeNone;

You need add the above in your -(void)viewDidLoad method.

Note: You should be using the latest GM release of iOS 7 and Xcode 5 now since the API has changed from beta versions.

这篇关于导航栏出现在带有新 iOS7 SDK 的视图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆