为什么我使用Addsubview添加其他控制器的视图,视图会向下移动20点?
我正在使用下面的代码来测试该问题。
- (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 上运行它们时,会出现这样的情况 图片
我很困惑,因为这个问题出现在我的项目中,但是当我使用系统的照片选择器时,它会显示正确。 所以,谁能帮帮我,非常感谢。
I am using the code below to test the problem.
- (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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,
UIViewController
的view
使用[[UIScreen mainScreen] applicationFrame]
值作为其框架。这通常用于状态栏,为(0, 20, 320, 460)
。因此,当您按层次添加视图时,您会发现视图向下推。By default,
UIViewController
'sview
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.