Controller <-> View 一般视图层级
2016-08-10 22:49
316 查看
关于 self.navigationController.view
相信看过 MBProgressHUD 官方例子HudDemo代码的同学应该看到过下述代码:
1 | HUD = [[MBProgressHUD alloc] initWithView:self.navigationController.view]; |
self.navigationController.view有些疑惑,这是什么玩意?其实,如果我们查看下
UINavigationController.h文件就会发现,
UINavigationController其实是继承自
UIViewController的,那么它拥有
view属性也就不奇怪了。
1 | NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationController : UIViewController |
self.navigationController.view到底是什么东西,稍安勿躁。
显示 MBProgressHUD
初始化 MBProgressHUD 时需要我们传入一个UIView类型的参数
view,而显示 MBProgressHUD 的原理其实就是用
addSubview方法将 MBProgressHUD 添加为这个
view的子视图。
我们先来看看未显示 MBProgressHUD 时,应用的视图层次结构。其中 1 为
UIWindow,即
self.view.window,2 是
UINavigationController的
view,即我们前面提到的
self.navigationController.view,3 为
self.view,4 为导航栏
UINavigationBar,即
self.navigationController.navigationBar。
通过这张图,我们清楚地看到了
self.view.window、
self.navigationController.view、
self.view和
self.navigationController.navigationBar在应用的视图层次中所处的位置,以及它们之间的层次关系。
下面,我们就对比一下 MBProgressHUD 分别在
self.view.window、
self.navigationController.view和
self.view上显示时应用的视图层次结构,以及导航栏上按钮的可用情况。
方式 1 - On self.view.window
使用这种方式时,MBProgressHUD 被添加到了self.view.window上,它与
self.navigationController.view在视图层次上是平级的,同为
self.view.window的子视图。但是由于 MBProgressHUD 是后添加的,所以它处于
self.navigationController.view的上方,因此导航栏上的按钮均不可点击。
方式 2 - On self.navigationController.view
使用这种方式时,MBProgressHUD 被添加到了self.navigationController.view上,它与
self.navigationController.navigationBar在视图层次上是平级的,同为
self.navigationController.view的子视图。但是由于 MBProgressHUD 是后添加的,所以它处于
self.navigationController.navigationBar的上方,因此导航栏上的按钮也均不可点击。
方式 3 - On self.view
使用这种方式时,MBProgressHUD 被添加到了self.view上,不管
self.view或 MBProgressHUD 是否占满整个屏幕,
self.navigationController.navigationBar永远处于 MBProgressHUD 的上方。因此,导航栏上的按钮一直是可点击的。
总结
当你需要让导航栏上的按钮不可点击的时候,可以选择使用方式 1或
方式 2显示 MBProgressHUD 。反之,可以选择
方式 3。
参考链接:
1.http://blog.leichunfeng.com/blog/2015/03/16/talking-about-the-usage-of-mbprogresshud-combined-with-reveal/
相关文章推荐
- IOS学习 ModalViewController模态视图的创建 两视图间用代理方式<传值>
- Unbalanced calls to begin/end appearance transitions for <IDOOrderHomeViewController: 0x8da2960>.
- IOS:Warning: Attempt to dismiss from view controller <xxxxxxxxxController: 0x15bd67f0> while a prese
- pass all options of <select> from View to controller
- <android5.0>之View state changes(视图状态改变)
- IOS6新特性集合视图<UICollectionView>CircleLayout实践
- Storyboard (<UIStoryboard: 0x15e989a0>) doesn't contain a view controller with identifier "***C"
- Assigning to 'id<UITextViewDelegate>' from incompatible type 'HBComposeViewController *const __stron
- Warning: Attempt to present <NextViewController: 0x10966fed0> on
- Assigning to ‘id<UIWebViewDelegate>’ from incompatible type 'xxxViewController *const __strong'
- MVC区域 视图必须派生自 WebViewPage 或 WebViewPage<TModel>
- Sending 'ViewController' to Parameter of Incompatible Type 'id<xxxDelegate>'
- asp.net mvc 如何将controller 里一个action 返回值为list<>的值输出到view
- IOS:Warning: Attempt to dismiss from view controller <xxxxxxxxxController: 0x13f6840e0>
- Unbalanced calls to begin/end appearance transitions for <IDOOrderHomeViewController: 0x8da2960>.
- Objective-C ,ios,iphone开发基础:多个视图(view)之间的切换,以及视图之间传值。使用parent <->dismiss
- springmvc <mvc:view-controller >
- OpenCV 2 学习笔记(13): 算法的基本设计模式<4> :使用Model-View-Controller模式创建一个应用程序
- Unity3D与iOS的交互设计<ViewController 的跳转>
- Sending 'ViewController *const __strong' to parameter of incompatible type 'id<***Delegate>'