tags:

views:

104

answers:

2

Hi guys.

I am trying to rotate the screen on the iphone. For example, First state of screen : is "Portrait". Then it calls "Landscape" screen. Following code is used for making Landscape screen :

- (void)viewDidLoad {
    [super viewDidLoad];
    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
    CGFloat angle = 90 * M_PI / 180;
    self.view.transform = CGAffineTransformMakeRotation(angle);
    self.view.center = [nRangeAppDelegate sharedAppDelegate].window.center;
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 480, 44)];
    label.textAlignment = UITextAlignmentLeft;
    label.numberOfLines = 2;
    label.text = @"12345\n67890";
    [self.view addSubview:label];
}

But above code shifted to right in 20 px.

How to make 480x320 view at point 0,0 no shifting ?

Thanks in advance.

A: 

Your window is shifted because the appDelegate window is not centred on the screen as it is drawn below the status bar

Try this:

self.view.center = CGPointMake(160.0, 240.0);

You must make sure you are adding this view to a normal viewcontroller (ie not a nav controller or similar). The easiest way to do this is to add it to the main application window, like so:

MyRoratedController *myCtrlr = [[MyRoratedController alloc] 
  initWithNibName:@"MyRoratedController" bundle:nil]; 
[window addSubview:[myCtrlr view]];

Note that if your app has a status bar shown you will have to change the 160 above to 150

pheelicks
Thanks for response. I've tried your code. But still same. The window is shifted to right 20px. I think this 20px is status bar's width.
Is the view you're trying rotate a subview of another view? The parent view may be positioning your view relative to itself. Also, what happens when you set the numbers in my answer to another value (eg 140.0, 240.0)? Does the view move?
pheelicks
My application navigation based application. All UIViewControllers have one UIView. When call the the view I am trying rotate, this code is used : MyRoratedController *myCtrlr = [[MyRoratedController alloc] initWithNibName:@"MyRoratedController" bundle:nil];[navigationController pushViewController: myCtrlr animated:NO];I've changed CGPointMake(160.0, 240.0) by many different values. But no changes. Please help. Guys.Thanks.
See my updated answer, I didn't realise you were using a nav controller before
pheelicks
A: 

My application navigation based application. All UIViewControllers have one UIView. When call the the view I am trying rotate, this code is used : MyRoratedController *myCtrlr = [[MyRoratedController alloc] initWithNibName:@"MyRoratedController" bundle:nil]; [navigationController pushViewController: myCtrlr animated:NO]; I've changed CGPointMake(160.0, 240.0) by many different values. But no changes. Please help. Guys. Thanks.