2011-11-16 50 views
0

我正在開發應用程序的所有方向在Ipad ....但在開發過程中,我只做了風景模式..但是我想改變所有可能的方向...在這裏,我得到了一些問題.... 這裏是代碼...關於在iPad的UIOrientation問題

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
//return YES; 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || UIInterfaceOrientationPortrait); 
} 

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [self adjustViewsForOrientation:toInterfaceOrientation]; 
} 

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation { 
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
    { 
     \\Here I did my stuff.. 
    } 
    else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     \\Here I did my stuff.. 
    } 
}  

的問題是,當模擬器啓動,如果伊茨在風景模式下,我得到的意見適當的大小,但如果模擬器處於potrait模式,我不能得到我想要的...如果我改變模擬器的方向,我會得到正確尺寸的視圖...

+0

嘗試此方法 - (無效)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation持續時間:(NSTimeInterval)持續時間 –

+0

事情是TAT我可以得到調整大小視圖文所述裝置改變取向(I thnk上述代表將被稱爲設備正在改變方向),bt我希望我的編譯器檢測設備的方向,而應用程序正在啓動並根據方向改變視圖的大小..我可以做這個嗎? – Icoder

+0

您必須爲界面構建器中的所有視圖配置支柱和彈簧。 – MadhavanRP

回答

1

這是同樣的問題,即w作爲面對。 和我解決它通過這樣做:

首先改變這一功能:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 

然後在viewDidLoad中功能,您可以檢查設備是否處於橫向或縱向模式。

-(void)viewDidLoad 
{ 
    if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) 
    { 
     //landscape view code 
    } 

    else 
    { 
     //portrait view code 
    } 

} 

hope this will help 
+1

老兄U巖它工作正常感謝您的職位..... – Icoder

+0

@icoder謝謝任何時間人:) –