首页 文章

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

提问于
浏览
8

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

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

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

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

enter image description here

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

enter image description here

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

enter image description here

enter 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时 . UIAlertView显示在iPad屏幕上(但不在电视屏幕上) . 电视的方向在我的iPad处于人像模式时变为风景(实际上这正是我真正想要做的)....

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

当UIAlertView出现时,有没有办法防止我的情况发生什么?这样可以解决问题..

4 回答

  • 1

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

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

    这有帮助吗?

  • 1

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

  • 1

    您可以尝试在视图上设置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;
    }
    

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

相关问题