开发者

Landscape Screen shifted to right in 20px

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.

Update:

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'v开发者_开发百科e changed CGPointMake(160.0, 240.0) by many different values. But no changes.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜