我在使用 CosmicMind Swift Material framework for swift ( https://github.com/CosmicMind/Material) 创建的 View 上有 SearchBar 和 TabBar。下面是我设置 View 的代码:
window = UIWindow(frame: Screen.bounds)
let tabBarControllers = [MySearchBar(rootViewController:ViewController2()), MySearchBar2(rootViewController:ViewController1())]
window!.rootViewController = TabBarController(viewControllers: tabBarControllers)
window!.makeKeyAndVisible()
所以基本上,我有标签栏,它有搜索栏,而搜索栏又有一个 View 。我为 View 创建了一个 xib,这样我就可以使用界面生成器拖放和定位东西。我遇到的问题是,标签栏覆盖了我的一些标签。请参阅下面的屏幕截图
当我运行我的应用程序时,我得到如下所示的 View 。如您所见,标签 2 在 View 之外,我已经尝试了所有可能的方法,但无法弄清楚并使 View 正确适合搜索栏和选项卡栏
任何帮助将不胜感激
最佳答案
您处理此问题的方式可能会变得比必要的更复杂。如果您要在 TabBar 的两个页面上都有一个 SearchBar,您应该做的是将 TabBar 设置为 SearchBar 的子项 (rootViewController),因此每个只有一个实例。然后在具有标签的 View Controller 中添加自动布局约束。那应该适合你:)
关于swift - Material swift : UIView with Searchbar and TabBar moves out of view swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44469971/