2010-06-30 64 views
1

我正在開發一個應用程序(我的第一個應用程序),它基本上是一個TabBar應用程序。 更準確地說,有: - 登錄視圖控制器 - 標籤欄控制器(登錄完成時) - 當TabBar的第一個itel從縱向切換到橫向時使用的橫向視圖控制器。Iphone:無法從我的橫向視圖切換回肖像視圖

因此,當我在第一個選項卡中時,我需要能夠移動到橫向視圖以顯示其他一些數據。在我的標籤欄控制器,我已經實現了這些方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
if([self selectedIndex] == 0) 
    return YES; 

return NO; 
} 


- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

// Get AppDelegate 
MyAppDelegate *delegate = [[UIApplication sharedApplication] delegate]; 

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) 
{ 
    // Remove TabBarView and add graph Landscape View 
    [self.view removeFromSuperview]; 
    [delegate setSubViewLandscapeViewController]; 
} 
} 

在委託,我已經實現了setSubViewLandscapeViewController和setSubViewTabBarController:我想landscapeViewController只在橫向模式下顯示

- (void)setSubViewTabBarViewController {  
[window addSubview:[tabBarController view]]; 
} 

- (void)setSubViewGraphLandscapeViewController { 
[window addSubview:[landscapeViewController view]]; 
} 

,然後我(在我的landscapeViewController):

- (void)viewWillAppear:(BOOL)animated { 
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight]; 
} 
// Override to allow orientations other than the default portrait orientation. 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations 
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

NSLog(@"willRotateToInterfaceOrientation"); 
} 

這部分工作正常,我的意思是從肖像切換到風景是好的(當我在第一個標籤中)時,tabbarcontroller將從SuperView中移除,而橫向視圖將作爲子視圖添加。

事情是......我不知道如何切換回肖像模式(然後使用我的委託的setSubViewTabBarViewController加載前一個控制器,tabBar一個)。似乎沒有任何willRotateToOrientation,willRotateFromOrientation,..當我實際上從橫向視圖移動設備時觸發...

總之,當我在景觀視圖時,我不知道該怎麼做才能移回來到tabbar視圖...我有一種卡在橫向視圖,一旦我在這一個。

非常感謝您的幫助,

呂克

回答

0

嗯,我設法得到了解決這個問題的方法。 事實上,從縱向移動到風景時,我從窗口子視圖中刪除了tabbarcontroller,而是添加了landscapeviewcontroller。 看來這不是正確的事情。 相反,我將landscapeViewController作爲tabbarcontroller的子視圖添加,並在從橫向到縱向時將其刪除。 我仍然有一個問題,但與這似乎當我連續做幾decive旋轉變化.... 關於景觀視野的y位置, 呂克

0

看的例子文件夾中CPTestApp-iPhone餅圖。它通過執行-(void)didRotateFromInterfaceOrientation:來處理旋轉,並在旋轉後調整圖形的大小。

+0

你好,其實嘛,我想我是不是真的很清楚:( 我需要加載一個lanscape視圖,當從縱向模式轉換爲橫向模式時,我finnaly設法通過shouldAutorotateToInterfaceOrientation和willRotateToInterfaceOrientation方法來處理這個問題。現在我正處於橫向模式,我不知道如何處理從橫向模式到縱向模式的旋轉......因爲我已經將UIView聲明爲橫向模式,在這種情況下是否觸發了一種方法?非常感謝 – Luc 2010-07-01 17:04:19