2009-11-28 70 views
2

我正在iPhone上開發一個應用程序。一種觀點支持縱向和橫向的定位。對於這兩種定位我有兩個單獨的視圖。該視圖頂部有一個UIToolbarUIToolBar和iPhone界面方向問題

問題是當我從風景改變回肖像時,頂部的UIToolbar消失。當我將toolbar旋轉回肖像時,我想讓它回到原來的位置。

這是我在做什麼在我的程序:

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) 
interfaceOrientation duration:(NSTimeInterval)duration {  
    if (interfaceOrientation == UIInterfaceOrientationPortrait) 
    { 
     self.view = self.portrait; 
     self.view.transform = CGAffineTransformIdentity; 
     self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); 
     self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0); 
    } 
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) 
    { 
     self.view = self.landscape; 
     self.view.transform = CGAffineTransformIdentity; 
     self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); 
     self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0); 
    } 
    else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     self.view = self.portrait; 
     self.view.transform = CGAffineTransformIdentity; 
     self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); 
     self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0); 
    } 
    else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) 
    { 
     self.view = self.landscape; 
     self.view.transform = CGAffineTransformIdentity; 
     self.view.transform = 
     CGAffineTransformMakeRotation(degreesToRadian(90)); 
     self.view.bounds = CGRectMake(0.0, 0.0, 460.0, 320.0); 
    } 
} 

我不知道我缺少什麼嗎?任何幫助將非常感激。

回答

1

,如果你想只是爲了讓你的看法可旋轉的,是足以實現

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

在viewCountroller類

+0

另外,您還需要在Interface Builder的佈局選項卡上設置錨點/拉伸設置。 – 2009-11-29 03:45:04

+0

我有兩個想要在縱向和橫向模式下交換的視圖。縱向視圖在頂部有一個工具欄,在首次啓動時顯示正常。但是,當我改變方向並將其設置回肖像工具欄消失。 – Leo 2009-11-29 10:58:01

1
self.view.bounds = CGRectMake(0.0, 0.0, 300.0, 480.0); 

這裏的問題是,你正在做的高480.但它應該是460.所以,你現在的高度已經超過了20px,這可能會使屏幕上的Toopbar稍微偏離屏幕。

+0

20px不會導致整個工具欄的消失。 iPhone的屏幕尺寸爲320x480。 – Morion 2009-11-29 09:02:44

+0

是的。我同意。這就是爲什麼我說「這可能會發送toopbar有點離開屏幕。」 。 :) – 2009-11-29 10:40:20

+0

嗨,大家好。感謝您的回覆。我嘗試設置較小的高度,但工具欄仍然不可見。任何想法? – Leo 2009-11-29 10:59:35

2

在界面構建器中,選擇工具欄,命中命令3;這將顯示標尺/對齊控制菜單。

在自動調整部分下,默認情況下,工具欄僅與左右和中心耦合。不是TOP。選擇頂部的「我」。現在工具欄相對於視圖頂部停靠,並且在旋轉過程中不會被推掉。

我敢肯定,這裏還有一個相當於此的代碼

+0

也有可能某些其他視圖未正確錨定(在Autosizing中),並且正在將其自身繪製在工具欄上。 – jlstrecker 2011-01-28 18:22:52