Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么使用Addsubview添加其他控制器';s视图,视图将向下移动20点?_Iphone_Uiviewcontroller_Addsubview - Fatal编程技术网

Iphone 为什么使用Addsubview添加其他控制器';s视图,视图将向下移动20点?

Iphone 为什么使用Addsubview添加其他控制器';s视图,视图将向下移动20点?,iphone,uiviewcontroller,addsubview,Iphone,Uiviewcontroller,Addsubview,我正在使用下面的代码来测试这个问题 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UIViewController *controller = [[UIView

我正在使用下面的代码来测试这个问题

- (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;
}
当我在模拟器或iphone上运行它们时,会发现
我很困惑,因为这个问题发生在我的项目中,但当我使用系统的照片选择器时,它看起来是正确的。
所以,谁能帮我,非常感谢。

默认情况下,
UIViewController的
视图使用
[[UIScreen mainScreen]applicationFrame]
值作为其框架。这通常用于状态栏,是
(0、20、320、460)
。因此,在按层次添加视图时,您会发现视图向下推。

您还应该看看我的答案。