Failed to add additional subview to uiwindow except rootviewcontroller

Below is my code from the application delegate in the didFinishLaunchingWithOptions file

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];

CGRect windowFrame = self.window.frame;
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, windowFrame.size.height-100, windowFrame.size.height, windowFrame.size.height)];
bottomView.backgroundColor = [UIColor redColor];
[self.window addSubview:bottomView];

//    self.viewController.view.frame = CGRectMake(0, 0, windowFrame.size.width, windowFrame.size.height-100);

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

return YES;

My ViewController is FreeForm, and its height is about 245. As you can see, I'm trying to set the bottom view with a height of 100 points.

I'm just trying to learn it.

But the view always fills the entire screen. If I comment on setting the view controller as a Windows rootviewcontroller, I can see it at the bottom of the screen.

What am I doing wrong? Please advice.

Thank.

+5
source share
3 answers

Instead

self.window.rootViewController = self.viewController; 

when i code

[self.window addSubview:self.viewController.view]; 

gave me the expected result, and it determines the size of the free form.

, rootviewcontroller, , XIB.

+3

[self.window bringSubviewToFront: bottomView];

bottomView ,

[[[[UIApplication sharedApplication] delegate] window] addSubview:bottomView];
+2

, , IB ( xib ), -, . , . , , viewDidAppear: ViewController, , - , .

0

All Articles