嗨,在 iOS 6 上使用自动布局时,我的 rootViewController 的“rootView”似乎根本无法正确调整大小。
我的 rootViewController 是从 nib 加载的,我将它添加到视图层次结构中,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
RootVC *rootVC = [[RootVC alloc] initWithNibName:@"RootVC" bundle:nil];
self.window.rootViewController = rootVC;
return YES;
}
但是当我旋转模拟器时,rootVC 的视图不会调整大小。由于您无法在 xib 中对“rootview”设置任何约束,因此我也尝试了此操作,但没有任何效果:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
RootVC *rootVC = [[RootVC alloc] initWithNibName:@"RootVC" bundle:nil];
self.window.rootViewController = rootVC;
NSArray *vConst = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:@{@"view" : rootVC.view}];
NSArray *hConst = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:@{@"view" : rootVC.view}];
[self.window addConstraints:vConst];
[self.window addConstraints:hConst];
return YES;
}
当我注销 rootvc 视图的帧大小时,它始终是纵向格式(w:768,h:1024)
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
NSLog(@"%f, %f", self.view.frame.size.width, self.view.frame.size.height);
}
有人可以告诉我我在这里缺少什么吗?我在这个问题上浪费了几个小时,却一无所获^^
谢谢