如何将UIView放在TabBarController的顶部

时间:2019-03-30 20:41:33

标签: ios swift xcode

我正在尝试创建一个辅助UIView(子视图),当用户单击它时,它将展开或折叠。该概念与“地图”应用(iOS)或Spotify相同。我不明白如何将视图锚定在标签栏控制器的顶部

我只是尝试更改HeightAnchor,但这样做无法使用UIView.animate方法

func expandView() {
        let newY = view.frame.height/4
        let newHeight = view.frame.height-newY

        UIView.animate(withDuration: 1.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
            self.subView.frame = CGRect(x: 0, y: newY, width: self.view.frame.width, height: newHeight)
        }) { (true) in
            self.subView.updateConstraintsIfNeeded()
            self.tableView.isHidden = true
            self.subViewExpanded = true
        }
    }

    func collapseView() {
        let newY = self.view.frame.height-80
        UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .curveEaseOut, animations: {
            self.subView.frame = CGRect(x: 0, y: newY, width: self.view.frame.width, height: 80)
        }) { (true) in
            self.subView.translatesAutoresizingMaskIntoConstraints = false

            if #available(iOS 11.0, *) {
                self.subView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true
            } else {
                // Fallback on earlier versions
            }
            self.tableView.isHidden = true
            self.subViewExpanded = false
        }
    }

实际结果将我的subView锚定在整个视图的底部,而不是标签栏的

0 个答案:

没有答案