我正在研究一個iPhone應用程序,該應用程序在單擊欄按鈕時出現的導航欄下有一個過濾器列表(下拉列表)。請告訴我該怎麼做。swift中的下拉列表
回答
有許多方法可以做到這一點,我的建議將是類似如下的內容:
當初始化視圖控制器,你的下拉菜單視圖偏移和隱藏的導航欄後面。根據您的首選設置,使用佈局約束或使用視圖的框架執行此操作。
var isAnimating: Bool = false
var dropDownViewIsDisplayed: Bool = false
func viewDidLoad() {
super.viewDidLoad()
let height: CGFloat = self.dropDownView.frame.size.height
let width: CGFloat = self.dropDownView.frame.size.width
self.dropDownView.frame = CGRectMake(0, -height, width, height)
self.dropDownViewIsDisplayed = false
}
接着的動作連接起來的BarButtonItem在按下時,顯示視圖是否隱藏或者如果使用動畫可見隱藏。
@IBAction func barButtonItemPressed(sender: UIBarButtonItem?) {
if (self.dropDownViewIsDisplayed) {
self.hideDropDownView()
} else {
self.showDropDownView()
}
}
func hideDropDownView() {
var frame: CGRect = self.dropDownView.frame
frame.origin.y = -frame.size.height
self.animateDropDownToFrame(frame) {
self.dropDownViewIsDisplayed = false
}
}
func showDropDownView() {
CGRect frame = self.dropDownView.frame
frame.origin.y = self.navigationBar.frame.size.height
self.animateDropDownToFrame(frame) {
self.dropDownViewIsDisplayed = true
}
}
func animateDropDownToFrame(frame: CGRect, completion:() -> Void) {
if (!self.animating) {
self.animating = true
UIView.animateWithDuration(0.5, delay: 0.0, options: .CurveEaseInOut, animations: {() -> Void in
self.dropDownView.frame = frame
}, completion: (completed: Bool) -> Void in {
self.animating = false
if (completed) {
completion()
}
})
}
}
所有留給你的是定義你的dropDownView並正確地連接它。
我希望幫助,請與評論,如果您有什麼不明白
感謝您的重播,+1的速度答案。我會檢查它然後我標記爲正確的答案 – Hazem 2015-03-03 10:56:45
偉大@Elliott(Y) – dip 2015-08-03 08:31:55
我也實現了這種方式,但在我的我添加了兩個UIButtons到下拉UIView。我在navigationController.navigationbar下面插入了下拉UIView。我的問題是我的點擊事件不起作用。有任何想法嗎 ? – DrPatience 2015-09-24 11:25:49
要使用下拉列表中的自定義視圖與泰伯維使用下面的鏈接https://github.com/lminhtm/LMDropdownView
@abirama該庫在Obj-C中,您有快速版本嗎? – 2016-12-22 05:06:54
在橋接頭的幫助下,您可以在Swift Project中使用Obj-C。 – 2017-10-04 06:54:20
- 1. 下拉列表ios swift
- 2. 下拉列表中的下拉列表
- 3. Yii填充另一個下拉列表中的下拉列表
- 4. swift中的命令下拉列表名稱
- 5. Excel中的下拉列表
- 6. MVC中的下拉列表
- 7. cakephp中的下拉列表
- 8. joomla中的下拉列表
- 9. Jaspersoft:iReport中的下拉列表
- 10. asp.net中的下拉列表
- 11. 下拉列表中的MVC
- 12. iframe中的下拉列表
- 13. hovermenuextender中的下拉列表
- 14. 下拉列表中的值
- 15. Webgrid中的下拉列表
- 16. MVC4中的下拉列表
- 17. 下拉列表中的GridView
- 18. Grails中的下拉列表
- 19. DetailsView中的下拉列表
- 20. 下拉列表中的列表項
- 21. 下拉列表中的列表框
- 22. Bootstrap下拉列表中的長列表
- 23. 的下拉列表
- 24. 下拉列表
- 25. 下拉列表
- 26. 下拉列表
- 27. 下拉列表
- 28. 下拉列表
- 29. 下拉列表中選中
- 30. 在Swift 3中創建一個下拉列表
創建一個文本框或搜索欄,和一個tableview下面你的導航欄。完成搜索後,刪除您的文本字段和tableview。 – 2015-03-03 10:18:15