2011-11-20 35 views
0

我試圖根據iPad的方向初始化我的UIViewController。 在initWithNibName,我使用下面的代碼:初始UIViewController取決於iPad的方向

CGSize size = self.view.frame.size; 
authForm = [[[AuthForm alloc] initWithFrame:CGRectMake(-400,(size.height-400)/2,400,400)] autorelease]; 
[self.view addSubview:authForm]; 

這是當應用在人像模式(倒置與否)啓動我想要什麼,但我想有這樣的,當它啓動在橫向模式(左或右):

authForm = [[[AuthForm alloc] initWithFrame:CGRectMake((size.width-400)/2,-400,400,400)] autorelease]; 

我怎麼能這樣做呢? 我已經用willAutorotateToInterfaceOrientation:試過幾件東西,但沒有奏效。

+0

檢查http://stackoverflow.com/questions/2825696/switch-between-multiple-views-while-respecting-orientation –

回答

0

好吧,我對這個主題的帖子顯然沒有足夠的瞭解。 我終於發現這一點:

if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) { 
    authForm = [[[AuthForm alloc] initWithFrame:CGRectMake((size.width-400)/2,-400,400,400)] autorelease]; 
} else { 
    authForm = [[[AuthForm alloc] initWithFrame:CGRectMake(-400,(size.height-400)/2,400,400)] autorelease]; 
} 

還是要謝謝你