【问题标题】:How to force TV out of iPad to be in Landscape mode even if iPad is in portrait mode即使 iPad 处于纵向模式,如何强制 iPad 上的电视处于横向模式
【发布时间】:2014-03-29 10:35:28
【问题描述】:

我正在使用 HDMI 电缆将我的 iPad 屏幕输出到电视。 如果我将 iPad 保持在横向模式,则电视上的输出会以横向模式显示。如果我将它旋转到电视上的纵向输出,也会更改为纵向模式。

有没有办法限制这一点,即即使我将 iPad 旋转到纵向,电视上的输出也应该保持横向

这里有一些图片可以说明我的问题

这是我 iPad 的方向...

这就是我得到的............

这就是我想要的......

从乱搞编程,我走到了这一步……

我在带有 IBaction 方法的 Xcode 的单视图应用程序模板中用一些图像在 UIImageView 上制作了一个按钮 这个方法有以下代码

- (IBAction)screenButton:(id)sender {
NSLog(@"Screen Count %d",[[UIScreen screens]count]);
if([[UIScreen screens]count] > 1) {

    CGSize max;

    UIScreenMode *maxScreenMode;

    for(int i = 0; i < [[[[UIScreen screens] objectAtIndex:1] availableModes]count]; i++)

    {

        UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:i];

        if(current.size.width > max.width)

        {
            max = current.size;

            maxScreenMode = current;

        }

    }

    //UIScreen *external = [[UIScreen screens] objectAtIndex:0];

    UIScreen *external = [[UIScreen screens] objectAtIndex:1];

    external.currentMode = maxScreenMode;



    //external_disp = [externalDisplay alloc];

    //external_disp.drawImage = drawViewController.drawImage;

    // ExternalDisplayOn = TRUE;
    //UIImageView *extView = [[UIImageView alloc] init];

     _extView.hidden=FALSE;

    _extView.frame = external.bounds;//MyMainScrollView.frame;

            UIWindow *newwindow = [[UIWindow alloc] initWithFrame:_extView.frame];

    //UIWindow *newwindow = [[UIWindow alloc];

            [newwindow addSubview:_extView];

            newwindow.screen = external;

            newwindow.hidden=NO;


    [[[UIAlertView alloc] initWithTitle:@"Alert Showed" message:[NSString stringWithFormat:@"_extView.frame X %f, Y %f, W %f, H %f, Screen Count %d",_extView.frame.origin.x,_extView.frame.origin.y,_extView.frame.size.width,_extView.frame.size.height,[[UIScreen screens]count]] delegate:nil cancelButtonTitle:@"OK!" otherButtonTitles:nil, nil] show];


            [newwindow makeKeyAndVisible];

    }

}

我能够在一定程度上解决我的问题,但我面临的问题如下

每当我运行应用程序并将其保持为纵向模式时,电视上的输出就是我 iPad 屏幕的精确复制品。

现在,当我按下已分配上面代码的 UIButton 时。一个 UIAlertView 出现在 iPad 屏幕上(但不在电视屏幕上)。并且我的 iPad 在纵向模式下电视上的方向变为横向(实际上这正是我真正想要做的)....

但是当我按下 UIalertView 的取消按钮来关闭警报视图时。电视输出方向再次变为纵向模式....

当 UIAlertView 出现时,有没有办法防止我的情况发生。这将解决问题..

【问题讨论】:

  • 您是为两个窗口分配相同的视图还是同一视图有 2 个不同的实例?
  • @Dev_Dash 你找到解决方案了吗?

标签: ios objective-c ipad uialertview uiscreen


【解决方案1】:

我不知道我的想法是否有帮助,或者您已经设置了这样的程序。

在项目检查器中,您可以强制 iPad 处于某个方向。那么你的应用程序只在这个方向上运行。

有帮助吗?

【讨论】:

    【解决方案2】:

    您应该为您的 newwindow.rootViewController 创建一个单独的 UIViewController,您可以在其中定义适当的支持方向 - https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations

    【讨论】:

      【解决方案3】:

      您可以尝试在 View 上设置 90 度变换并将其边界更改为屏幕边界但交换大小组件。

      类似:

      CGRect screenBounds = external.bounds;
      _extView.transform = CGAffineTransformMakeRotation((CGFloat)M_PI_2);
      _extView.bounds = CGRectMake(0,0,screenBounds.size.height, screenBounds.size.width);
      

      【讨论】:

        【解决方案4】:

        您可以使用应用程序委托随意设置应用程序方向。

        - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
        {
        NSLog(@"Interface orientation Portrait = %@",enablePortrait);
        if(wantAppliactionTobeLandscape)
            return UIInterfaceOrientationMaskLandscapeRight;
        
        else 
            return UIInterfaceOrientationMaskPortrait;
        }
        

        相应地制作一个布尔值并根据需要进行设置。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2014-10-27
          • 1970-01-01
          • 2014-03-04
          • 2015-06-23
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多