下拉列表中迅速

我正在使用iPhone应用程序,该应用程序在单击栏button时出现的导航栏下有一个筛选器列表(下拉列表)。 请build议我该怎么做。

在这里输入图像说明

有很多方法可以做到这一点,我的build议可能类似于以下内容:

当初始化视图控制器时,下拉视图会偏移并隐藏在导航栏的后面。 使用布局约束或使用视图的框架,这取决于您的首选设置。

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,当按下时,显示隐藏的视图或隐藏(如果使用animation可见)。

 @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并正确地连接它。

我希望有帮助,如果有什么不明白的地方,请发表评论

要使用下拉列表自定义视图和Tableview使用下面的链接https://github.com/lminhtm/LMDropdownView