加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – swift中的下拉列表

发布时间:2020-12-15 01:51:57 所属栏目:百科 来源:网络整理
导读:我正在开发一个iPhone应用程序,它在我单击栏按钮时出现的导航栏下面有一个过滤列表(下拉列表).请建议我怎么做. 解决方法 有很多方法可以做到,我的建议类似于以下内容: 初始化视图控制器时,下拉视图会偏移并隐藏在导航栏后面.使用布局约束或使用视图的框架执
我正在开发一个iPhone应用程序,它在我单击栏按钮时出现的导航栏下面有一个过滤列表(下拉列表).请建议我怎么做.

解决方法

有很多方法可以做到,我的建议类似于以下内容:

初始化视图控制器时,下拉视图会偏移并隐藏在导航栏后面.使用布局约束或使用视图的框架执行此操作,具体取决于您的首选设置.

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并正确链接它.

我希望有所帮助,请评论是否有任何您不理解的内容

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读