关于self.view.window与viewDidLoad、viewWillAppear、viewDidAppear
在进入一个界面(UIViewController),如果要在进入的时候使用self.view.window,那么必须在将使用代码放在viewDidAppear方法中,而viewDidLoad、viewWillAppear中self.view.window.frame为0{{0,0},{0,0}}。
- (void)viewDidLoad { NSLog(@"viewDidLoad"); [super viewDidLoad]; } -(void)viewWillAppear:(BOOL)animated{ NSLog(@"viewWillAppear"); [super viewWillAppear:animated]; } -(void)viewDidAppear:(BOOL)animated{ NSLog(@"viewDidAppear"); [super viewDidAppear:animated]; [self _doTest01]; } - (void)_doTest01 { NSLog(@"_doTest01"); //UIView UIView* vwFullScreenView = [[UIView alloc]init]; vwFullScreenView.backgroundColor=[UIColor yellowColor]; vwFullScreenView.frame=self.view.window.frame; NSLog(@"%@",NSStringFromCGRect(vwFullScreenView.frame)); [self.view.window addSubview:vwFullScreenView]; //UILabel UILabel* lblTitle = [[UILabel alloc]init]; lblTitle.text=@"显示了@_@"; lblTitle.frame=CGRectMake(0, 0, 200, 40); lblTitle.textAlignment=NSTextAlignmentCenter; lblTitle.backgroundColor=[UIColor whiteColor]; lblTitle.center=vwFullScreenView.center; [vwFullScreenView addSubview:lblTitle]; }
输出:
2015-11-01 09:21:27.031 demo010[7638:261914] viewDidLoad
2015-11-01 09:21:27.032 demo010[7638:261914] viewWillAppear
2015-11-01 09:21:27.038 demo010[7638:261914] viewDidAppear
2015-11-01 09:21:27.038 demo010[7638:261914] _doTest01
2015-11-01 09:21:27.039 demo010[7638:261914] {{0, 0}, {320, 568}}
如果将[self _doTest01];代码放到viewDidLoad 或 viewWillAppear 方法中,那么输出结果如下:
2015-11-01 09:35:00.054 demo010[7762:271018] viewDidLoad
2015-11-01 09:35:00.054 demo010[7762:271018] viewWillAppear
2015-11-01 09:35:00.054 demo010[7762:271018] _doTest01
2015-11-01 09:35:00.054 demo010[7762:271018] {{0, 0}, {0, 0}}
2015-11-01 09:35:00.061 demo010[7762:271018] viewDidAppear
可以看到self.view.window的frame为 {{0, 0}, {0, 0}},说明此时self.view.window还没显示出来。
相关推荐
self.view.insertSubview(self.leftViewController.view, atIndex:0) } } if self.centerViewController != nil{ if (self.centerViewController.view.superview == nil){ self.addChildViewController...
_cuiPickerView.frame = CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, 200); //这一步很重要 _cuiPickerView.myTextField = _textField; _cuiPickerView.delegate = self; _...
self.scrollView.contentSize = CGSize(width: self.view.bounds.size.width * 3, height: hBounds/2) //Putting a subview in the navigationbar to hold the titles and page dots navbarView = UIView() ...
ios7 demo下载 searchbar与状态栏重叠已修复。 关键代码: -(void)viewDidLoad{ [super viewDidLoad]; // self.table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];//去除多余行 //设置table...
学长发我的,我无耻的分享给大家了。 希望大家对于那些 viewdidload viewwillappear 的调用顺序有个了解。
self.indexView = [[MJNIndexView alloc]initWithFrame:self.view.bounds]; self.indexView.dataSource = self; self.indexView.fontColor = [UIColor blueColor]; [self.view addSubview:self.indexView]; ...
self.view.backgroundColor = [UIColor whiteColor]; self.title = @" bsy_Window 演示"; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setFrame:CGRectMake([UIScr
:fishing_pole: 生命周期挂钩 :fishing_pole:关于LifecycleHooks允许将自定义代码注入到视图和视图控制器中,以响应生命周期事件,例如, viewController.on(.viewDidAppear) { animated inprint("View did appear",...
self.view.backgroundColor = [UIColor whiteColor]; [self initpicCount:9]; // Do any additional setup after loading the view, typically from a nib. } /** 初始化 最大可以选照片的张数 @...
pullUpView = [[StyledPullableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height + 180)]; pullUpView.openedCenter = CGPointMake(160 + xOffset,self....
// self.view.backgroundColor = [UIColor grayColor]; // // StBtnTouchMove *stBtn = [[StBtnTouchMove alloc]initWithFrame:CGRectMake(0, 200, 375, 100)]; // [self.view addSubview:stBtn]; // stBtn....
各个ViewController的 viewDidLoad , viewWillAppear, viewDidAppear,viewWillDisAppear, viewDidDisappear都会正确的执行(翻页到对应的ViewController时才会调用viewDidLoad, viewWillAppear,viewDidAppear....
override func viewDidLoad() { super.viewDidLoad() self.navBarBgAlpha = 0 self.navBarTintColor = .white } func scrollViewDidScroll(_ scrollView: UIScrollView) { if scrollView....
颜色透明度调整:0-100- (void)viewDidLoad {[super viewDidLoad];UIProgressView *progress = [[UIProgressView alloc]initWithFrame:CGRectMake(0, 100, 100, 40)];[self.view addSubview:progress];oooview = [...
项目中创建表格, 引用头文件 ... self.view.backgroundColor = [UIColorwhiteColor]; CGFloat margin = 10.f; CGFloat width = self.view.frame.size.width -2*margin; // - 添加表格 - 两列 WBDataGrid
1.ViewController .m - (void)viewDidLoad { [super viewDidLoad]; self.title = @隐藏导航栏; UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom... [self.view addSubview:button]; self.navigat
作者klop,源码KLParallaxView,模仿 Apple TV 显示菜单的... self.parallaxView = [[KLParallaxView alloc] initWithFrame:self.view.bounds subviews:subviews]; [self.view addSubview:self.parallaxView]; }
SayGift_3DBanner_View *Banner_View = [[SayGift_3DBanner_View alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)]; Banner_View.delegate = self; [Banner_View show3DBannerView]; ...
[self.view addSubview:headScrollView]; CGFloat Width= 320; CGFloat Height= 200; UIImageView * firstImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, Width, Height)]; ...
ScollLabelNumber导入文件 SliderLabelContainer.h SliderLabelContainer.m StarView.h StarView.m使用方法- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor whiteColor]; self....