Swift: how to show a tab bar controller after a login view

前端 未结 5 1312
抹茶落季
抹茶落季 2021-01-30 22:45

I have seen many posts similar to this here but they are all about Objective-C while I am developing my app in Swift. As you can see from the image I have a login screen view an

5条回答
  •  星月不相逢
    2021-01-30 23:34

    func setTabBarVisible(visible:Bool, animated:Bool) {
    
    //* This cannot be called before viewDidLayoutSubviews(), because the frame is not set before this time
    
        // bail if the current state matches the desired state
        if (tabBarIsVisible() == visible) { return }
    
        // get a frame calculation ready
        let frame = self.tabBarController?.tabBar.frame
        let height = frame?.size.height
        let offsetY = (visible ? -height! : height)
    
        // zero duration means no animation
        let duration:NSTimeInterval = (animated ? 0.3 : 0.0)
    
        //  animate the tabBar
        if frame != nil {
            UIView.animateWithDuration(duration) {
                self.tabBarController?.tabBar.frame = CGRectOffset(frame!, 0, offsetY!)
                return
            }
        }
    }
    
    func tabBarIsVisible() ->Bool {
        return self.tabBarController?.tabBar.frame.origin.y < CGRectGetMaxY(self.view.frame)
    }
    
    // Call the function from tap gesture recognizer added to your view (or button)
    
    @IBAction func tapped(sender: AnyObject) {
        setTabBarVisible(!tabBarIsVisible(), animated: true)
    }
    

提交回复
热议问题