开发者

Why I Use Addsubview to add other controller's view,the view will move down 20point?

开发者 https://www.devze.com 2023-03-15 03:36 出处:网络
I am using the code below to test the probl开发者_如何学Pythonem. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

I am using the code below to test the probl开发者_如何学Pythonem.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIViewController *controller = [[UIViewController alloc] init];
    controller.view.backgroundColor = [UIColor whiteColor];
    [window setRootViewController:controller];
    UIViewController *controller2 = [[UIViewController alloc] init];
    [controller.view addSubview:controller2.view];
    controller2.view.backgroundColor = [UIColor yellowColor];
    UIViewController *controller3 = [[UIViewController alloc] init];
    controller3.view.backgroundColor = [UIColor purpleColor];
    [controller2.view addSubview:controller3.view];
    [window makeKeyAndVisible];
    return YES;
}

and when I run them on simulator or iphone,it will appear that image

I'm very puzzled because this problem occur in my project,but when I used system's photo picker,it will appear right. So,who can help me,thank you very much.


By default, UIViewController's view uses the [[UIScreen mainScreen] applicationFrame] value as its frame. This usually accounts for the status bar and is (0, 20, 320, 460). So you find the view's pushing downwards as you add them hierarchically.

0

精彩评论

暂无评论...
验证码 换一张
取 消