我试图在 UITabBar 顶部获得一个视图,一旦使用 Swift 视图出现在它上面,标签栏就会隐藏起来 [英] I am trying to get a view on top of a UITabBar where the tab bar is hidden once the view appears on it using Swift
问题描述
我正在尝试在 UITabbar 上添加一个视图.视图出现后,我希望标签栏隐藏自身.下面我附加了一个我想创建的视图(底部有按钮的视图).我在它后面有一个标签栏,我希望一旦我们点击带有三个点的图标就会出现这个视图.这是我想要创建的视图
I am trying to add a view on top of UITabbar. Once the view appears ,I want the tab bar to hide itself. Below I am attaching a view that I want to create (the bottom view that has buttons on it). I have a tab bar behind it and I want this view to appear once we click on the icon with three dots. This is the view that I want to create
我添加了以下代码以在选项卡栏上显示视图,但它与中心对齐,我不知道如何将其置于底部.我尝试使用约束,但这没有用.附加我在故事板中创建的视图:我想在标签栏上显示这个视图它现在是一个虚拟视图.>
I added below code to present a view over tabbar but it is aligning to the centre and I am not aware how to bring it to the bottom. I tried using constraints but that didn't work. Attaching the view i created in storyboard: I want to show this view on tab bar Its a dummy view for now.
Code:
func showViewOnEyeBtnPressed() {
self.view.addSubview(showViewOnEyeBtn)
showViewOnEyeBtn.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
showViewOnEyeBtn.alpha = 0
showViewOnEyeBtn.center = self.view.center
UIView.animate(withDuration: 0.4) {
self.showViewOnEyeBtn.alpha = 1
self.showViewOnEyeBtn.transform = CGAffineTransform.identity
}
}
注意:在尝试了评论中的建议后,我的视图如下所示:添加建议后查看 我希望绿色视图在隐藏后占据标签栏视图.
Note: After trying suggestions from the comment my view looks like this: View after adding suggestions I want that green view to occupy the tab bar view once it is hidden.
推荐答案
问题是 - 你在 UIViewController.view
上调用它,你的 UIViewController
嵌入在其中UITabBarController
.
The problem is that - you are calling this on UIViewController.view
where your UIViewController
is embedded inside the UITabBarController
.
你应该在 UITabBarController.view
实例上调用如下 -
You should call following on UITabBarController.view
instance like -
func showViewOnEyeBtnPressed() {
guard let targetView = self.tabBarController?.view ?? self.view else { return }
targetView.addSubview(showViewOnEyeBtn)
showViewOnEyeBtn.transform = CGAffineTransform.init(scaleX: 1.3, y: 1.3)
showViewOnEyeBtn.alpha = 0
showViewOnEyeBtn.center = self.view.center
self.tabBarController?.tabBar.isHidden = true
UIView.animate(withDuration: 0.4, animations: {
self.showViewOnEyeBtn.alpha = 1
self.showViewOnEyeBtn.transform = CGAffineTransform.identity
}, completion: { (_) in
self.tabBarController?.tabBar.isHidden = false
})
}
这篇关于我试图在 UITabBar 顶部获得一个视图,一旦使用 Swift 视图出现在它上面,标签栏就会隐藏起来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!