2009-11-23 27 views
2

編輯2:當我啓動應用程序而沒有狀態欄在最上面時,所有的行爲都按照計劃進行。有了狀態欄,我無法按照自己的意願行事。它看起來好像UINavigationController通過減去狀態欄的20個像素來不斷調整內容視圖的大小。我不知道。調整iPhone的keywindow的主視圖的大小

我創建了一個簡單的基於UINavigationController的應用程序。此導航控制器中的根視圖是一個UITableView。在某個特定時間,我想從底部向上滑動80像素的高度。頂部的整個視圖(由UINavigationController控制的視圖)應調整大小,並縮小80像素以騰出空間放置新底部視圖。

這基本上是我用來重新定位視圖的代碼:

-(void)showTeaser { 
float adHeight = 80; 

[adView setFrame:CGRectMake(0.0,self.navigationController.view.bounds.size.height, 320.0, 80.0)]; 
[[[UIApplication sharedApplication] keyWindow] addSubview:adView]; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[adView setAlpha:1.0]; 
[adView setFrame:CGRectMake(0.0,self.navigationController.view.bounds.size.height-adHeight, 320.0, 80.0)]; 
[self.navigationController.view setFrame:CGRectMake(0.0,0.0, 320.0, self.navigationController.view.bounds.size.height-adHeight)]; 

[self.view setFrame:CGRectMake(0.0, 0, 320.0, self.view.bounds.size.height-adHeight)]; 

[UIView commitAnimations]; } 

我降低了導航欄的α,設定的UITableViewController的視圖爲紅色。新的觀點是紫色的。

這是發生了什麼事。首先截圖初始狀態。一切都看起來很正常。第二張屏幕截圖顯示更改幀後的狀態。 UITableviewController的視圖始終在導航欄下推動20個像素。另外,如果我嘗試向keywindow添加更多視圖,它們總會比我預期的高20個像素。它幾乎看起來像鍵窗口(減去導航欄)被推高了20個像素。

編輯1:不管我調整什麼尺寸來看,它總是20像素。

讓我的加欣賞到keywindow都錯了嗎?我不應該這樣做嗎?

alt text http://www.hans-schneider.de/iphone-seo/1.pngalt text http://www.hans-schneider.de/iphone-seo/2.png

+0

我已經玩過我的tableviewcontrollers視圖的自動確定屏蔽,但這並沒有改變基本問題。 – Haentz 2009-11-23 10:45:05

回答

0

您是否嘗試過用你的tableview的變換屬性,而不是手動更改它的框架?它可能會更好,因爲框架取決於原點,您只需要改變它的大小。

1

爲了解決這個問題,我將UINavigationController的子視圖作爲UIView的子視圖,並手動設置了「UINavigationController」視圖的邊界。

//outerView is a UIView defined in the interface 
outerView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);]; 

//mainNavigationController is a UINavigationController defined in the interface 
//rootViewController is a UIViewController (or inherited class) defined in the interface and instanced before this code 
mainNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; 

//set the frame for the view of the navigation controller - 20 is due to the status bar 
mainNavigationController.view.frame = CGRectMake(0.0, 20.0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 20); 

後來的後來,當我去調整,我調整父「的UIView」,而不是「UINavigationController的」視圖。

//change the outer view's frame to resize everything 
//adHeight is a float defined earlier 
outerView.frame = CGRectMake(0.0, 20.0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - 20 - adHeight); 

這在動畫序列中效果很好。

編輯2011-05-12:我更新了outerView框架來填滿屏幕。這必須設置爲允許觸摸事件。