将抽屉添加到UITabBarController

问题描述

我需要在UITabBarController顶部添加一个抽屉,这样

  1. 抽屉始终位于UITabBarController的顶部。用户可以将抽屉拉到全屏,并且抽屉也可以将其他视图控制器推到其上方。

  2. 选项卡中的视图控制器不应与此抽屉重叠。

尝试了一些类似的操作,在UITabBarControlle中添加CustomDrawer:

import React,{ Component } from 'react';

export enum AuthStatus {
  isLoggedIn = "isLoggedIn",isNotLoggedIn = "isNotLoggedIn",Uninitialized = "uninitialized"
}

export enum Progressstatus {
  InProgress = "InProgress",Uninitialized = "Uninitialized",Done = "Done",Error = "Error"
}

class AuthenticationShell extends Component {

  state = {
    authStatus: AuthStatus.Uninitialized,user: undefined
  }

  componentDidMount = () => {
    // this function will launch when the component is mounted to the dom
    this.getCurrentUser()
  }

  getCurrentUser = () => {
    Auth.currentAuthenticatedUser().then(user => {
      // if user is authenticated update authStatus & user state here
      this.setState({
        authStatus: AuthStatus.isLoggedIn,user: user.attributes.email
      })
    }).catch(e => {
      // if user is not authenticated update authStatus
      this.setState({ authStatus: AuthStatus.isNotLoggedIn })
    });
  }

  render() {
    const { authStatus } = this.state;
    switch (authStatus) {
      case AuthStatus.isLoggedIn:
        return (
          <div>
            <LoggedInContainer />
          </div>
        )
      case AuthStatus.isNotLoggedIn:
        return (
          <div>
            <LoginForm />
          </div>
        )
      default: return null;
      // when authstatus is Uninitialized or not isLoggedIn and not isNotLoggedIn null will be rendered
      // Rendering null while waiting on some async function is not ideal
    }
  }
}

export default AuthenticationShell;

但是我无法拉起抽屉,因为它已嵌入在选项卡中,而且customDrawerViewOverTabBar与选项卡中的实际viewController重叠。我需要使其成为Tabbar本身的一部分。

尝试增加标签栏的大小以嵌入视图:

fileprivate惰性var defaultTabBarHeight = {tabBar.frame.size.height }()

override func viewDidLoad() {
    super.viewDidLoad()
    let customDrawerViewOverTabBar = CustomDrawer(frame: CGRect(x: 0,y: -self.tabBar.frame.size.height,width: 30,height: 30));
    tabBar.addSubview(customDrawerViewOverTabBar)
}

但是,它没有为添加自定义视图而创建空间,而是拉伸了选项卡图标。

感谢任何帮助/指导!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)