112 iphone objective-c ipad ios ios7
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];
Run Code Online (Sandbox Code Playgroud)
在早期版本中,它正常工作.搜索栏显示在statusbar导航栏下方.该tableview是出现在搜索栏下方
但是当我运行它时Xcode 5 sdk iOS 7,搜索栏不可见(我认为它位于状态栏和导航栏下),并且导航栏也出现在表视图上.
是否可以通过iOS 7稳定释放来修复?
还是我编码的问题?
或者我们应该通过添加y (y = statubar height + nav bar height)值来处理它iOS 7?
我最近下载了Xcode 5 DP来测试我在iOS 7中的应用程序.我注意到并确认的第一件事是我的视图边界并不总是调整大小来考虑状态栏和导航栏.
在viewDidLayoutSubviews中,我打印视图的边界:
{{0, 0}, {320, 568}}
Run Code Online (Sandbox Code Playgroud)
这导致我的内容出现在导航栏和状态栏下方.
我知道我可以通过获取主屏幕的高度,减去状态栏的高度和导航栏的高度来解释自己的高度,但这似乎是不必要的额外工作.
还有其他人遇到过这个问题吗?
更新:
我找到了解决这个特定问题的方法.将导航栏的半透明属性设置为NO:
self.navigationController.navigationBar.translucent = NO;
Run Code Online (Sandbox Code Playgroud)
这将修复视图在导航栏和状态栏下面的框架.
但是,当您希望导航栏为半透明时,我还没有找到解决此案例的方法.例如,在全屏查看照片时,我希望导航栏是半透明的,并且要在其下方构建视图.这是有效的,但当我切换显示/隐藏导航栏时,我经历了甚至更奇怪的结果.第一个子视图(a UIScrollView)每次都会更改其边界.
One*_*rew 188
这不完全正确.iOS 7中引入了一个新属性,可让您像以前版本的iOS一样调整布局行为.将这段代码放在视图控制器中,你应该好好去!导航栏占用的空间应自动计算
if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
Run Code Online (Sandbox Code Playgroud)
您需要在-(void)viewDidLoad方法中添加以上内容.
注意:您应该使用iOS 7和Xcode 5的最新GM版本,因为API已从beta版本更改.
MQo*_*der 37

如果您正在使用Storyboard(我强烈推荐!),这就是解决方案: 您可以在storyboard中禁用ViewController的"Extend Edges".您必须为每个viewController执行此操作.您可以通过单击stortyboard中的viewController图标(除了视图本身下面的productOwner)然后选择属性检查器(如图像显示)来禁用扩展边缘.
这也将设置像iOS 6的对齐线.
xCode 5中另一个很棒的工具是"预览":点击管家按钮(助理编辑器)并选择预览.在那里你可以选择iOS 6,看看你的故事板设计在iOS 6上会是什么样子.
它很棒:D
[更新]
注意:当应用程序在iOS7上进入后台时,禁用"扩展边缘"可能会导致导航栏上出现黑光.在多任务视图上也可以看到发光(双击主页按钮).这可以通过将导航栏视图的背景颜色设置为白色来解决.
[self.navigationController.view setBackgroundColor:[UIColor whiteColor]];
Run Code Online (Sandbox Code Playgroud)
Bid*_*ids 12
As the OP says, there is a simple solution to this which is to set the navigation bar to be opaque. Rather than doing this in code, simply untick "Translucent" for your root navigation bar:

小智 8
self.edgesForExtendedLayout=UIRectEdgeNone;
它适用于iOS 7模拟器(Xcode 5 DP5)