即使iPad处于纵向模式,如何强制电视从iPad进入横向模式

时间:2014-02-26 14:17:16

标签: ios objective-c ipad uialertview uiscreen

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

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

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

这是我的iPad定位......

enter image description here

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

enter image description here

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

enter image description hereenter image description here

从乱搞编程我到目前为止......

我在XII的单个视图应用程序模板中使用IBaction方法在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出现时,有没有办法防止我的情况发生什么事。这样可以解决问题..

4 个答案:

答案 0 :(得分:1)

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

在projekt检查员中,您可以强制iPad处于某个方向。然后您的应用仅以此方向运行。

有帮助吗?

答案 1 :(得分:1)

答案 2 :(得分:1)

您可以尝试在视图上设置90度变换,并将其边界更改为屏幕边界,但交换尺寸组件。

类似的东西:

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

答案 3 :(得分:1)

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

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

else 
    return UIInterfaceOrientationMaskPortrait;
}

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

相关问题