2013-09-26 27 views
0

我對iPhone/iPad的開發非常陌生。你能幫我創建這個程序化。我想以編程方式展開/摺疊UIView。如何在IOS上展開和摺疊uiview

任何人都知道該怎麼做,或者我可以按照任何教程?我試圖找到教程,但無法找到我想要的。

下面是截圖我想怎麼辦

enter image description here

+0

你使用的是TableView? – user1673099

回答

10

及其與修改查看bneely建議的高度,輕鬆完成..

遵循以下步驟:

1.首先創建第二個視圖你在你的問題發佈什麼,並命名爲「detailedView」

2.如果你有 「detailedView」 HEIGHT = 200(例如),寫在viewDidLoad方法如下代碼,

CGRect newFrame = detailedView.frame; 

    newFrame.size.height = 100; 

    detailedView.frame = newFrame; 

所以當 「detailedView」 負載,這將是看起來像第一個查看你在你的問題中顯示的內容。

3.當你按一下按鈕,展開「detailedView」,該按鈕操作中只寫了下面的代碼

CGRect newFrame = detailedView.frame; 

    if(newFrame.size.height == 100) 
    { 
     newFrame.size.height = 200; 
     [UIView animateWithDuration:0.25 animations:^(void){ 
     detailedView.frame = newFrame; 
     }]; 
    } 
    else 
    { 
     newFrame.size.height = 100; 
      [UIView animateWithDuration:0.25 animations:^(void){ 
      detailedView.frame = newFrame; 
      }]; 
    } 

這就是全部。

3
CGRect newFrame = view.frame; 
    newFrame.size.height += 100; 
    [UIView animateWithDuration:0.25 animations:^(void){ 
    view.frame = newFrame; 
    }];