【发布时间】:2023-10-19 19:07:01
【问题描述】:
像往常一样,我有一个 UIViewController 的子类。当我加载应用程序时,我需要调整一些必须以编程方式放入的元素的大小。当然,大小取决于界面方向:所以,我做到了:
- (void)viewDidLoad {
switch( [self interfaceOrientation] ) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationPortraitUpsideDown:
NSLog(@"Portrait");
break:
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
NSLog(@"Landscape");
break;
}
但无论模拟器/设备的方向如何,在 viewDidLoad/WillAppear 中情况始终是纵向的,即使一切都正确旋转。 在 Plist 中,我添加了所有支持的方向。 提示?
【问题讨论】:
-
遇到了完全相同的问题!这一直是模拟器中的一个问题。最好的是:插入“willRotate”,它会告诉你它将旋转到横向。接下来它在 layoutSubview 中中断。如果你检查那里的方向,它是纵向的!什么鬼?
-
你应该重写
shouldAutorotateToInterfaceOrientation并在那里返回YES不是很明显吗?如果您这样做了,请将您的代码移至该方法。
标签: uiviewcontroller uiinterfaceorientation