gpt4 book ai didi

ios - 在 iOS 7 中,状态栏和导航栏出现在我的 View 边界之上

转载 作者:IT王子 更新时间:2023-10-29 07:24:26 25 4
gpt4 key购买 nike

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

viewDidLayoutSubviews 中,我打印 View 的边界:

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

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

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

我该如何解决这个问题?

更新:

我已经找到了针对这个特定问题的解决方案。将导航栏的半透明属性设置为 NO:

self.navigationController.navigationBar.translucent = NO;

这将修复 View 在导航栏和状态栏下方的框架。

但是,当您希望导航栏为半透明时,我还没有找到解决方法。例如,全屏查看照片时,我希望导航栏是半透明的, View 在其下方框起来。这行得通,但是当我切换显示/隐藏导航栏时,我遇到了更奇怪的结果。第一个 subview (UIScrollView)每次都改变其边界 y 原点。

最佳答案

您可以通过在 iOS7 SDK 中实现一个名为 edgesForExtendedLayout 的新属性来实现这一点。请添加以下代码来实现此目的,

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

您需要在您的 -(void)viewDidLoad 方法中添加以上内容。

iOS 7 brings several changes to how you layout and customize the appearance of your UI. The changes in view-controller layout, tint color, and font affect all the UIKit objects in your app. In addition, enhancements to gesture recognizer APIs give you finer grained control over gesture interactions.

Using View Controllers

In iOS 7, view controllers use full-screen layout. At the same time, iOS 7 gives you more granular control over the way a view controller lays out its views. In particular, the concept of full-screen layout has been refined to let a view controller specify the layout of each edge of its view.

The wantsFullScreenLayout view controller property is deprecated in iOS 7. If you currently specify wantsFullScreenLayout = NO, the view controller may display its content at an unexpected screen location when it runs in iOS 7.

To adjust how a view controller lays out its views, UIViewController provides the following properties:

  • edgesForExtendedLayout

The edgesForExtendedLayout property uses the UIRectEdge type, which specifies each of a rectangle’s four edges, in addition to specifying none and all. Use edgesForExtendedLayout to specify which edges of a view should be extended, regardless of bar translucency. By default, the value of this property is UIRectEdgeAll.

  • extendedLayoutIncludesOpaqueBars

If your design uses opaque bars, refine edgesForExtendedLayout by also setting the extendedLayoutIncludesOpaqueBars property to NO. (The default value of extendedLayoutIncludesOpaqueBars is NO.)

  • automaticallyAdjustsScrollViewInsets

If you don’t want a scroll view’s content insets to be automatically adjusted, set automaticallyAdjustsScrollViewInsets to NO. (The default value of automaticallyAdjustsScrollViewInsets is YES.)

  • topLayoutGuide, bottomLayoutGuide

The topLayoutGuide and bottomLayoutGuide properties indicate the location of the top or bottom bar edges in a view controller’s view. If bars should overlap the top or bottom of a view, you can use Interface Builder to position the view relative to the bar by creating constraints to the bottom of topLayoutGuide or to the top of bottomLayoutGuide. (If no bars should overlap the view, the bottom of topLayoutGuide is the same as the top of the view and the top of bottomLayoutGuide is the same as the bottom of the view.) Both properties are lazily created when requested.

请引用,apple doc

关于ios - 在 iOS 7 中,状态栏和导航栏出现在我的 View 边界之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17074365/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com