1

こんにちは、iOS 6 で autolayout を使用している場合、rootViewController の「rootView」が適切にサイズ変更されていないようです。

私の rootViewController はペン先からロードされ、次のようにビュー階層に追加しています:

- (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);

}

誰かが私がここで欠けているものを教えてもらえますか? 私はこの問題で何時間も無駄にしましたが、どこにも行きません^^

どうも

4

1 に答える 1

1

iOS 6 の自動レイアウト機能では、多くのことがうまくいかないようです。制約が曖昧で、View Controller で translatesAutoresizingMaskIntoConstraints を無効にできないと、多くの競合が発生する可能性があります。そのため、lldb で autolayoutTrace メソッドを呼び出して、制約にあいまいさがないようにしてpo [[UIWindow keyWindow] _autolayoutTrace] ください。あいまいさがある場合は、それらを解決する必要があります。

于 2012-10-10T08:39:55.360 に答える