我想我已经浏览了几乎所有关于这个主题的帖子。所以在你阅读之前不要扼杀这个问题。这个问题是针对 iOS 7 上的 XCode 5
我有一个同时支持横向和纵向模式的应用程序。在我的项目部署信息中,检查了所有方向。
当应用启动时我显示
- v1ViewController(应始终以横向模式打开)
当用户点击一个按钮时,它会将他们带到
- v3ViewController(应始终以纵向模式打开)
我遇到的问题是,当应用程序启动并且我将 iPhone 置于纵向模式时,它会显示此内容。
如果我在横向模式下切换 iphone,它会显示这个。
如何强制我的 v1ViewController 始终显示横向模式?
这是我现在拥有的代码。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return YES;
}
else
{
return NO;
}
}
但是如果我添加这个,那么 View 总是像我显示的第一张图片一样打开,并且旋转没有效果。
- (BOOL)shouldAutorotate
{
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
NSLog(@"interfaceOrientation: %d ...", interfaceOrientation);
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
return YES;
}
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return YES;
}
else
{
return NO;
}
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight;
}
最佳答案
对于任何对我的工作原理感兴趣的人,这就是我所做的。
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
关于iphone - Xcode 5 中的 UIInterfaceOrientation 横向与纵向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18988163/