美文网首页
UINavigationBar的层级结构

UINavigationBar的层级结构

作者: 学习无底 | 来源:发表于2016-01-29 11:21 被阅读680次

最近,看了标哥的博客-《iOS导航标题不居中问题》(原文地址http://www.henishuo.com/ios-nav-center-question/)不甚理解,特看了下UINavigationBar的层级结构

我没有自定义左边item,用的系统的item。打印了navigationBar的subviews,结果如下:

class:_UINavigationBarBackground: 0x7a8f7130; frame = (0 -20; 320 64); autoresize = W; userInteractionEnabled = NO; layer =>0x7a8f6830>>,,,superClass:_UIBarBackgroundImageView;

class:UINavigationItemView: 0x7a8f4450; frame = (106 8; 108 27); opaque = NO; userInteractionEnabled = NO;layer = <CALayer: 0x7a8f4500>>,,,,superClass:UIView;

class:UIButton: 0x7a7bbd70; frame = (6 7; 30 30); opaque = NO; layer =<CALayer:0x7a7bbe90>>,,,,superClass:UIControl;

class:<UIView: 0x7a7ba490; frame = (274 2; 40 40); layer =<CALayer: 0x7a7ba520>>,,,superClass:UIResponder

class:<_UINavigationBarBackIndicatorView: 0x7a839550; frame = (8 11.5; 13 21); alpha = 0; opaque = NO; userInteractionEnabled = NO; layer =<CALayer: 0x7a839520>>,,,superClass:UIImageView.

_UINavigationBarBackground就是整个NavigationBar

UINavigationItemView是前一个页面的titleView

UIView是前一个页面的右边的item,

UIButton是返回按钮,设置[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];设置的是返回按钮的背景图,要设置偏移量,不然图会被严重拉伸

_UINavigationBarBackIndicatorView是我们看到的那个返回剪头图片,所以设置self.navigationBar.backIndicatorImage = image;是设置的不是返回按钮的图片

UIBarButtonItem会放在UINavigationItem中,UINavigationItem在UINavigationBar的items中。当我们没有设置backBarButtonItem时,UINavigationItem中的backBarButtonItem也为nil。

_UINavigationBarBackground与_UINavigationBarBackIndicatorView在navigation不断push新controller过程中不会创建新对象,但UIButton在subviews中并没有找到。并且backBarButtonItem与UIButton、_UINavigationBarBackIndicatorView的显示关系还没有找到,backButtonTitle相对应的显示关系也没有找到,等待继续发掘。

相关文章

网友评论

      本文标题:UINavigationBar的层级结构

      本文链接:https://www.haomeiwen.com/subject/ytgbhttx.html