2011-10-17 129 views
1

在我的應用程序中,我有2個視圖,portraitView和landScapeView。而且我的應用程序還包括許多視圖...在橫向和縱向視圖中旋轉的問題

  1. 當我啓動應用程序時,橫向和縱向視圖並排顯示。

  2. 當我在landscapeview中啓動應用程序時,portraitview正在顯示..later旋轉後返回視圖正在變得適當。

我使用下面給出的代碼......所以,請建議我什麼都改變應該做提到克服以上問題..

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

{ 

if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { 
    NSLog(@"LANDSCAPE>>"); 
    portraitView.hidden = YES; 
    landscapeView.hidden = NO; 

    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic_landscape.jpg"]]; 
    self.view.backgroundColor = background; 



} 
else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight){ 
    NSLog(@"LANDSCAPE<<"); 
    portraitView.hidden = YES; 
    landscapeView.hidden = NO; 
    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic_landscape.jpg"]]; 
    self.view.backgroundColor = background; 

    self.view.hidden = NO; 

} 
else{ 
    portraitView.hidden = NO; 
    landscapeView.hidden = YES; 


    NSLog(@"Portrait"); 
    UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic.jpg"]]; 
    self.view.backgroundColor = background; 

    background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg-ic2.jpg"]]; 
    self.view.backgroundColor = background; 

} 

return YES; 
+0

爲什麼要爲風景和肖像製作不同的視圖?爲什麼你沒有相應地根據你所處的方位來固定框架尺寸? –

+0

要更清楚您只需要使用一個視圖。以編程方式或通過適合的界面構建器設置視圖的框架。 – iamsult

回答

1

聽起來像你的portraitView和landscapeView都在應用程序的初始啓動時可見。上述代碼僅在定位在運行時更改時執行。如果您堅持使用單獨的視圖進行縱向和橫向視圖,那麼您還需要在啓動時檢測方向,並適當地顯示/隱藏視圖。

1

,系統調用shouldAutorotateToInterfaceOrientation事實:並不意味着它會在那裏那麼做。您想要使用willRotateToInterfaceOrientation和didRotateFromInterfaceOrientation,並儘可能使用自動調整大小。您也可以繼承佈局更新回調以重新排列視圖。不建議使用兩個視圖並將它們顯示/隱藏爲橫向/縱向。

相關問題