2010-03-10 102 views
1

我正在研究一個模塊,當我得到它時,屏幕處於橫向模式。我必須加載一個新的視圖,並切換到肖像模式。雖然這看起來很簡單,但我一直無法找到一個簡單的解決方案。以下是我的嘗試:加載視圖時如何從橫向旋轉到縱向?

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; 
locationsView =[[LocationsViewController alloc] initWithNibName:@"LocationsViewController" bundle:nil]; 
[self.view addSubview:locationsView.view]; 

而且沒有像我需要的那樣工作。它將狀態欄旋轉到縱向模式,但不是視圖的其餘部分。

有什麼建議嗎?

托馬斯

回答

1

這做到了:

[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait]; 
self.view.transform = CGAffineTransformIdentity; 
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); 
    //resize the view 
self.view.bounds = CGRectMake(0.0, 0.0, 320, 460); 
self.view.center = CGPointMake(240, 140); 

locationsView =[[LocationsViewController alloc] initWithNibName:@"LocationsViewController" bundle:nil]; 
[self.view addSubview:locationsView.view]; 

並確保degreesToRadian在global.h定義。

相關問題