您好在iOS 6上使用autolayout时,我的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);
}
有人可以告诉我我在这里缺少什么吗?我已经浪费了几个小时来解决这个问题并且无处可去^^THX
答案 0 :(得分:1)
iOS 6的自动布局功能似乎可能出现很多问题。约束中的歧义以及未能在视图控制器中禁用translatesAutoresizingMaskIntoConstraints会导致很多冲突。因此,通过在lldb中调用autolayoutTrace方法,确保约束中没有歧义:po [[UIWindow keyWindow] _autolayoutTrace]
如果存在歧义,则必须解决它们。