【发布时间】:2014-07-01 19:26:45
【问题描述】:
我想制作一个 iPhone 应用程序,它在 iPhone 处于纵向模式时显示一个视图,而在 iPhone 处于横向模式时显示另一个。 我知道有很多关于这个的帖子,但我不明白答案。
为了理解,我第一次使用选项卡式应用程序进行测试,因为我已经有两个视图。当我点击第二个屏幕时,我希望我的 iPhone 处于横向模式。 (并且在第一个纵向模式中)。
在 Apple 网站和 stackoverflow 上,我看到了以下代码:
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation
{
if ((orientation == UIInterfaceOrientationPortrait) ||
(orientation == UIInterfaceOrientationLandscapeLeft))
return YES;
return NO;
}
或类似的代码。
在我的主故事板中,我将第二个视图放在横向,带有界面。
但是当我运行我的应用程序并点击第二个屏幕时,iPhone 保持纵向模式..
我尝试用单视图应用程序做同样的事情,并用 .xib 文件创建了新文件 (landscapeViewController),但我无法得到一个完美的结果!
【问题讨论】:
-
您可以尝试以编程方式切换模式:stackoverflow.com/questions/10670834/…
-
这个方法
[[UIDevice currentDevice] setOrientation: UIDeviceOrientationLandscapeLeft];在iOS7中不起作用(只读)这个代码也是一样的:if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice] orientation])) { UIWindow *window = [[UIApplication sharedApplication] keyWindow]; UIView *view = [window.subviews objectAtIndex:0]; [view removeFromSuperview]; [window addSubview:view]; }(非常奇怪的代码......)
标签: iphone objective-c landscape