2012-01-09 35 views
0

我正在開發一個應用程序,支持縱向和橫向模式。定向支持在ios5中

我通過改變視圖幀和資產規模在

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 
self.view.frame = CGRectMake(0,0,1024,768); 
} 

其實現這一目標中的iOS4.3及以下正常工作。

當我試圖運行在Xcode4.2和ios5.0模擬器方向不明確。我的意思是,當從縱向更改爲橫向時,不適合屏幕(框架尺寸小於實際橫向框架尺寸)。

任何想法爲什麼它發生?

非常感謝, 阿維

回答

2

應用框架時的方向變化實際發生的嘗試xcode4.2和iOS 5對方向更改有一些快速響應,其他視圖和控件都得到了改進,所以它不適合您,因此您可以在didRotateFromInterfaceOrientation中嘗試它。o r willRotateFromInterfaceOrientation它現在可以正常工作。

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    //support for all orientation change 
    return YES; 
} 
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{ 
// in iOS statusBarOrientation is correct than all other orientation changes 
if(UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) 
    self.view.frame = CGRectMake(0,0,1024,768); 
else 
    self.view.frame = CGRectMake(0,0,768,1024); 

} 
+0

@ balakrishnan非常感謝你。:-) – Avi 2012-01-09 13:36:11

0

入住酒店的方位支持設置 並與這一個

這與狀態欄

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{ 

if(interfaceOrientation == UIInterfaceOrientationPortrait){ 
    self.view.frame = CGRectMake(0,0,768,1004); 
} 
else{ 
    self.view.frame = CGRectMake(0,0,1024,748); 
} 
} 
+0

嘗試不工作...只有身高正在變化.. – Avi 2012-01-09 08:09:01

+0

你能顯示你的viewDidLoad代碼嗎? – Hiren 2012-01-09 08:38:31

+0

使用xib設計了視圖。所以不要在viewdidLoad中寫任何東西。它只是 - (void)viewDidLoad {super viewDidLoad]; } – Avi 2012-01-09 09:15:01