Bri*_*ood 7 iphone cocoa-touch
我有三个ViewControllers设置来处理三个视图.我遇到的问题是在模拟器中方向是LandscapeRight(这是我想要的),并且第一个视图在该横向视图中正确显示,但是当我移动到第二个和第三个视图时,它们会出现逆时针旋转90度,手机屏幕左下角的视图左上角.我一直在尝试调试这几天,最接近我的线索是通过以下方式进行跟踪:
以下是我的app delegate的applicationDidFinishLaunching:
NSLog(@"1");
[window addSubview:welcomeController.view];
NSLog(@"2");
[window addSubview:goalController.view];
NSLog(@"3");
[window addSubview:planningController.view];
NSLog(@"4");
[window bringSubviewToFront:welcomeController.view];
NSLog(@"5");
Run Code Online (Sandbox Code Playgroud)
我的每个ViewControllers实现类似于以下内容的东西(唯一的变化是在传递给NSLog的字符串中切换出控制器的名称):
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
NSLog(@"called for WelcomeController");
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)
有了这个,我在控制台上得到以下输出:
a
called for WelcomeController
called for WelcomeController
called for WelcomeController
called for WelcomeController
2
called for GoalController
3
called for PlanningController
4
5
Run Code Online (Sandbox Code Playgroud)
我觉得有趣的是,对于添加的第一个视图,shouldAutorotateToInterfaceOrientation被调用4次,而其他两个只被调用一次.我希望这可能是因为它首先必须进行一些设置(我相信模拟器在纵向模式下启动,所以它可能在进行旋转时调用它),但我发现相关性有点可疑.
我已经切换了顺序,以便首先为goalController调用addSubview,然后调用welcomeController.在这种情况下,它是以正确的横向方向显示的goalController(它通常是欢迎控制器).这似乎消除了我的XIB文件和ViewControllers本身.我不确定为什么调用addSubview的第一个视图是特殊的.我也尝试在索引0使用insertSubview,结果相同.
| 归档时间: |
|
| 查看次数: |
6321 次 |
| 最近记录: |