如何强制使iPad的电视输出处于横屏模式,即使iPad处于纵向模式下。

8
我正在使用HDMI电缆将iPad屏幕的输出传输到电视。
如果我将iPad保持在横屏模式,电视上的输出就会呈现横向模式。如果我将其旋转为纵向,则电视上的输出也会改变为纵向模式。
有没有办法限制这一点?即使我将iPad旋转到纵向方向,电视上的输出也应该保持在横向。
这里有一些图片可以清楚地说明我的问题。
这是我的iPad的方向...
enter image description here
这是我得到的...
enter image description here
这是我想要的...
enter image description hereenter image description here
通过编程调试,我已经实现了以下过程:
我创建了一个带有图像的UIImageView按钮,在Xcode的单个视图应用程序模板中使用了一个IBAction方法,该方法具有以下代码:
- (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时,在iPad屏幕上会出现一个UIAlertView(但不会显示在电视屏幕上)。而且,TV的方向会从我的iPad的竖屏模式变为横屏模式(实际上这正是我想要做的)....
但是,当我按下UIalertView的取消按钮以关闭alertView时,TV输出的方向再次改变为竖屏模式....
有没有办法防止发生在我的情况中的事情,当UIAlertView出现时。这将解决问题..

你是将同一个视图分配给两个窗口,还是有两个不同的相同视图实例? - cescofry
@Dev_Dash 你有找到任何解决方案吗? - Monika Patel
4个回答

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

类似于:

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

1

您可以使用应用程序代理设置应用程序的方向。

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

else 
    return UIInterfaceOrientationMaskPortrait;
}

相应地创建一个布尔值,并将其设置为所需的。

1
我不知道我的想法是否有帮助,或者你已经像这样设置了你的程序。
在项目检查器中,您可以强制 iPad 处于特定方向。然后您的应用程序仅在此方向下运行。
这有帮助吗?

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接