2013-01-09 48 views
0

我目前正在開發iPhone應用程序,其中有一個ImageView展示一些圖像並通過刷卡可以更改圖像。iOS添加頂部欄作爲子視圖

但我目前正在嘗試添加一個子視圖,它將成爲頂級欄,當圖片被觸摸時,它會使頂部欄從頂部向下滑動。

當前的代碼我試着做到這一點的是:

CGRect frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 60.0f); 
UIView *topBar = [[UIView alloc] initWithFrame:frame]; 
[self.view addSubview:topBar]; 
[self.view bringSubviewToFront:topBar]; 

但頂欄會顯示不出來,我有記錄顯示,觸摸被認可。

我該如何做,以及如何正確填充按鈕的子視圖?

最好的問候。

FreeSirenety

回答

2

你的頂欄沒有任何關係,所以你怎麼能知道它已添加?

CGRect frame = CGRectMake(0.0f, 0.0f, self.view.frame.size.width, 60.0f); 
UIView *topBar = [[UIView alloc] initWithFrame:frame]; 
topBar.backgroundColor = [UIColor redColor]; 
[self.view addSubview:topBar]; 

而且你不需要使用bringSubViewToFront因爲這是被添加作爲一個子視圖總是在視圖層次中最頂層的看法!