iphone - Xcode 5 中的 UIInterfaceOrientation 横向与纵向问题

标签 iphone ios xcode

我想我已经浏览了几乎所有关于这个主题的帖子。所以在你阅读之前不要扼杀这个问题。这个问题是针对 iOS 7 上的 XCode 5

我有一个同时支持横向和纵向模式的应用程序。在我的项目部署信息中,检查了所有方向。

当应用启动时我显示

  • v1ViewController(应始终以横向模式打开)

当用户点击一个按钮时,它会将他们带到

  • v3ViewController(应始终以纵向模式打开)

我遇到的问题是,当应用程序启动并且我将 iPhone 置于纵向模式时,它会显示此内容。

enter image description here

如果我在横向模式下切换 iphone,它会显示这个。

enter image description here

如何强制我的 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/

相关文章:

ios - 如何在 iOS 中更改 UIImage 颜色?

iphone - iOS 推送通知问题

ios - 自动生成的 NSManagedObject 中的属性

iphone - 非 ARC 和弱属性 - ios 5

ios - 在等待调用委托(delegate)时如何让主线程休眠?

ios - drawRect() 画了一个自定义的形状,为什么不能填充颜色?

ios - 无法从表中打开 Safari

ios - 不能在顶部放置栏按钮?

ios - 如何调整 UISearchDisplayController 的搜索栏大小

ios - Overpass API - URL 获取,不适用于 iPhone,适用于 mac