iOS7中的status Bar问题

http://nsdifficult.com/blog/20131015/ios7statusbarproblem/



首先推荐这篇文章:Redesign Your App for iOS 7 之 页面布局

在iOS7中状态栏默认透明,且视图默认全屏。在实际开发中发现当直接在一个UIVIewController中添加一个UITableview时会发生table中内容在status bar后面的问题。

status bar cover view

苹果官网有个解决办法: How do I prevent the status bar from covering my views in iOS 7?

实际试验后发现对其他视图(如UIToolBar)都有效。但在storyboard环境下,在一个UIViewController上直接添加一个UITableView时,使用这种方法并不奏效,网上有讨论说这是一个bug。见:iOS 7: UITableView shows under status bar

后来使用:

1
[self.tableViewMain setContentInset:UIEdgeInsetsMake(20, self.tableViewMain.contentInset.left, self.tableViewMain.contentInset.bottom, self.tableViewMain.contentInset.right)];

解决问题。

解释

topLayoutGuide

上面的解决办法中有提到UIVIewController的属性topLayoutGuide

topLayoutGuide是只有在auto Layout时使用,指出屏幕内容垂直方向最高的内容显示范围。

1
@property(nonatomic, readonly, retain) id<UILayoutSupport> topLayoutGuide

更详细见:topLayoutGuide

iOS7中的status bar

iOS7中状态栏只有两种style:

1
2
3
4
5
6
7
typedef NS_ENUM(NSInteger, UIStatusBarStyle) {
    UIStatusBarStyleDefault                                     = 0, // Dark content, for use on light backgrounds
    UIStatusBarStyleLightContent     NS_ENUM_AVAILABLE_IOS(7_0) = 1, // Light content, for use on dark backgrounds
    
    UIStatusBarStyleBlackTranslucent NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 1,
    UIStatusBarStyleBlackOpaque      NS_ENUM_DEPRECATED_IOS(2_0, 7_0, "Use UIStatusBarStyleLightContent") = 2,
};

可见只剩默认(深色背景时使用)UIStatusBarStyleDefault和浅色背景时使用的UIStatusBarStyleLightContent两种style。

iOS7中我们通过ViewController重载方法返回枚举值的方法来控制状态栏的隐藏和样式

1
2
3
4
5
6
7
8
9
- (UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

- (BOOL)prefersStatusBarHidden
{
    return NO;
}

并需要在Info.plist配置文件中,增加键:UIViewControllerBasedStatusBarAppearance,并设置为YES

在需要刷新状态栏样式的时候,调用[self setNeedsStatusBarAppearanceUpdate]方法即可刷新

iOS7中UIViewController如何展示views及一些属性解释

iOS 7 UI Transition Guide

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.

即edgesForExtendedLayout是一个类型为UIExtendedEdge的属性,指定边缘要延伸的方向。默认UIRectEdgeAll,即四周边缘都延伸。

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.)

当使用UIScrollView或其子类(如UITableView)时,当automaticallyAdjustsScrollViewInsets=YES时,它会自动设置相应的内边距。UIScrollView会占据整个视图,又不会让导航栏遮盖。

extendedLayoutIncludesOpaqueBars

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

当Bar使用了不透明图片时,视图是否延伸至Bar所在区域,默认值时NO。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.

topLayoutGuide, bottomLayoutGuide指定了顶部或者底部的bar的边缘在UIViewController中view里的位置。

 Oct 15th, 2013


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值