2014-04-11 21 views
0

我是iPhone開發人員的初學者,無法創建可展開的視圖。就像點擊tableview行一樣,它們擴展到更多行。我想用一些標題創建兩個標題,當用戶首先點擊,然後他們的詳細視圖打開時,agin點擊詳細視圖就會隱藏動畫。第二個標題相同。如何在不使用iOS中的tableview的情況下創建展開式視圖

這兩個標題之間應該有一些區別。 請幫幫我。我在這個鏈接的圖片中找到了關於我的需求的鏈接,但無法實現。

+0

爲什麼你不能使用一個表視圖,如果你知道該怎麼做? – Wain

+0

感謝您的回覆,其實只有兩個標題在我的情況下,在他們的點擊一個細節視圖打開他們的底部,並再次隱藏點擊該標題,我可以創建相同的圖像顯示在這個http:// stackoverflow。 com/questions/1944428/how-to-implement -a-accordion-view-for-iphone-sdk-app。如果是的請引導我,我也想確認我可以在我的項目中使用https://github.com/appsome/AccordionView Library並根據我的要求對其進行修改。請幫幫我。 – KDRocks

回答

0

你可以有一個UIView其高度爲0,然後展開它在你的按鈕,當點擊:

UIView *expandableView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,0)]; 
expandableView.backgroundColor = [UIColor redColor]; 
expandableView.alpha = 0; 

然後當你點擊這個按鈕,你做一個動畫

[self.view addSubview:expandableView]; 
CGRect newFrame = expandableView.frame; 
newFrame.size.height = 100; 

//If this is the first view you would have to move the second header below 
CGRect newHeaderFrame = header2.frame; 
newHeaderFrame.origin.y += expandableView.frame.size.height; 

[UIView animateWithDuration:0.3 animations:^{ 
    expandableView.frame = newFrame; 
    expandableView.alpha = 1; 
    header2.frame = newHeaderFrame; 
}]; 

而且當你想縮小它:

CGRect newFrame = expandableView.frame; 
newFrame.size.height = 0; 

//If this is the first view you would have to move back to header 2 
CGRect newHeaderFrame = header2.frame; 
newHeaderFrame.origin.y -= newFrame.size.height; 

[UIView animateWithDuration:0.3 animations:^{ 
    expandableView.frame = newFrame; 
    expandableView.alpha = 0; 
    header2.frame = newHeaderFrame; 
} completion:^{ 
    [expandableView removeFromSuperview]; 
}]; 
+0

非常感謝,但是有兩個標題,那麼如何管理容器高度,就意味着有兩個標題大家在點擊展開然後第一個用戶點擊第一個然後第一個展開,第二個會自動顯示在第一個展開的視圖的底部。請告訴我,如何管理此 – KDRocks

+0

如果只有第二個標頭要移動,則可以在動畫中更改其框架。我剛剛編輯了我的答案。但如果有其他意見,我會強烈建議使用UITableView。 – streem

+0

手段,我必須使用tableview並隱藏他們的邊框並添加爲子視圖。請告訴我是否工作,因爲我必須在視圖底部添加這些擴展視圖,其他視圖部分已經用一些標籤和imageView填充。 – KDRocks

相關問題