【发布时间】:2011-10-17 04:11:35
【问题描述】:
我之前问过一个类似的问题,但现在我做了更多的工作,并提出了一个更精致的问题。
我的 applicationDidFinishLaunching: 中有以下代码,创建 3 个视图并将它们添加为窗口的子视图:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
GLViewController* controller = [[GLViewController alloc] init];
self.glViewController = controller;
[controller release];
glView = [[GLView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
glView.controller = glViewController;
[glView stopAnimation];
[window addSubview:glView];
invisibleView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
invisibleView.alpha = 1.0;
invisibleView.tag = 2;
// By the definition of UIViewAutoresizing, 0x3F corresponds to resizing in every direction.
invisibleView.autoresizingMask = 0x3F;
obstaclesViewController = [[ObstaclesViewController alloc] init];
obstaclesViewController.view = invisibleView;
[window addSubview:invisibleView];
viewController = [[GazeIntroViewController alloc] initWithNibName:@"GazeIntroViewController" bundle:[NSBundle mainBundle]];
[viewController.view setFrame:[[UIScreen mainScreen] bounds]];
[window addSubview:viewController.view];
[window bringSubviewToFront:viewController.view];
[window makeKeyAndVisible];
NSLog(@"window: %@", [window description]);
NSLog(@"window subviews: %@", [[window subviews] description]);
}
该应用程序应该只能在横向运行,所以我已将它(在 plist 中)设置为横向启动,它确实如此。但最后添加的子视图(GazeIntroViewController)出现旋转了 90 度。 (好像设备仍然是纵向的)。
真正让我困惑的是,第一个和第二个视图看起来都不错。如果我取出添加 invisibleView 的中间块,那么 GazeIntroViewController 也会正确显示。从 NSLogs 中,我可以看到正确显示的视图自动应用了变换([0, 1, -1, 0, 0, 0]),但是 我不明白为什么要应用这个变换对于某些视图而不是其他视图,当它们的父视图是所有视图的窗口时。
不添加invisibleView时的输出:
2011-07-31 21:00:51.271 GazeDemo[53515:207] window: <UIWindow: 0xa713ab0; frame = (0 0; 768 1024); autoresize = RM+BM; layer = <CALayer: 0xa713b90>>
2011-07-31 21:00:51.277 GazeDemo[53515:207] window subviews: (
"<GLView: 0x68bc350; frame = (0 0; 768 1024); layer = <CAEAGLLayer: 0x68bc4e0>>",
"<UIView: 0x68c3ce0; frame = (0 0; 748 1024); transform = [0, 1, -1, 0, 0, 0]; autoresize = LM+W+RM+TM+H+BM; layer = <CALayer: 0x68c2150>>"
)
添加invisibleView时的输出:
2011-07-31 21:11:05.489 GazeDemo[53710:207] window: <UIWindow: 0x689d4d0; frame = (0 0; 768 1024); autoresize = RM+BM; layer = <CALayer: 0x689d5b0>>
2011-07-31 21:11:05.496 GazeDemo[53710:207] window subviews: (
"<GLView: 0x689cf50; frame = (0 0; 768 1024); layer = <CAEAGLLayer: 0x689dcb0>>",
"<UIView: 0x68a05f0; frame = (0 0; 748 1024); transform = [0, 1, -1, 0, 0, 0]; autoresize = LM+W+RM+TM+H+BM; tag = 2; layer = <CALayer: 0x68a06c0>>",
"<UIView: 0x6b484b0; frame = (0 0; 768 1024); autoresize = LM+W+RM+TM+H+BM; layer = <CALayer: 0x6b4bad0>>"
)
【问题讨论】:
标签: ios objective-c ipad uiview autoresizingmask