8

I am using HDMI cable to take output of my iPad screen to a TV. if i keep the iPad in landscape mode the output on TV shows in landscape mode. and if i rotate it to portrait output on TV changes to portrait mode also.

Is there a way to restrict this i.e. even if i rotate iPad to portrait orientation the output on TV should remain in Landscape

Here are some images which will make clear my question

this is my iPad's orientation...

enter image description here

This is what i am getting.........

enter image description here

This is what i want......

enter image description here OR enter image description here

From messing around with programming i have come this far..

I have made a button over a UIImageView with some image, in a single view application template of Xcode with an IBaction method this method have the following code

- (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];

    }

}

I was being able to solve my problem by some extent, but the problem i am facing is like the following

whenever i run the app and keep it in portrait mode, the output on TV is the exact replica of my iPad screen .

now when i press the UIButton which i have assigned the code above. a UIAlertView shows up on the iPad screen (but not on the TV screen). and the orientation on TV changes to Landscape with my iPad in Portrait mode(actually this was exactly what i really wanted to do)....

but when i press the cancel button of UIalertView to dismiss the alert view. the orientation on TV output again changes to portrait mode....

is there a way to prevent whats happening in my case, when a UIAlertView shows up. this would solve the issue ..

Dev_Dash
  • 376
  • 3
  • 7

4 Answers4

1

I don't know whether my idea helps or you already set you program up like this.

In the projekt inspector you can force you iPad to be in a certain orientation. Then your app is only running in this orientation.

Does it helps?

Xcoder
  • 31
  • 5
1

You should make a separate UIViewController for your newwindow.rootViewController where you can define appropriate supported orientations - https://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations

LorikMalorik
  • 2,001
  • 1
  • 14
  • 14
1

You could try setting a 90 degree transform on the View and changing it's bounds to the screen's bounds but with the size components swapped.

Something like:

CGRect screenBounds = external.bounds;
_extView.transform = CGAffineTransformMakeRotation((CGFloat)M_PI_2);
_extView.bounds = CGRectMake(0,0,screenBounds.size.height, screenBounds.size.width);
chedabob
  • 5,835
  • 2
  • 24
  • 44
1

You can set your applications orientation as you like using your application delegate.

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

else 
    return UIInterfaceOrientationMaskPortrait;
}

make a bool accordingly and set that as required.

Syed Ali Salman
  • 2,894
  • 4
  • 33
  • 48