I am newbie in iOS and Swift. I am currently working on an application where I am required to show a tab bar with a big button in the center. Given the time constraints, what I have done is I created a button in the Window and positioned it on top of the Tab Bar programatically. Now when I navigate to or away from this screen, I am adding / removing this button in viewDidAppear and viewDidDisappear respectively. This makes sure that as tab bar goes away the button is also not shown and similarly when tab bar is shown the button is also added on top. However, because the addition and removal happens in viewDidAppear and viewDidDisappear, there is a slight delay in rendering and removing of the button because of which a momentary flickr is seen. Doing the same in viewWillAppear and viewWillDisappear doesn't work at all. The button doesn't show up or gets hidden in 'will' methods. Can someone please suggest what probably would be going wrong here? Thanks in advance. I am attaching a screen shot to give a rough idea about how it is supposed to look.
Asked
Active
Viewed 155 times
1
-
You can try Hiding that button to stop Flickering Effect instead of removing, not a solution but this would also work, I have also seen while I add my CALayer Classes it take little time to load – iOS Geek Jun 22 '18 at 04:13
-
I think it's not proper way, you should add button in view of tabbarcontroller – SPatel Jun 22 '18 at 04:14
-
https://stackoverflow.com/a/48293806/6630644 – SPatel Jun 22 '18 at 04:16
-
iOS Geek, thanks for the reply. We tried hiding as well, but it's giving the same result. It causes a momentary flicker. My best guess is because Tab bar gets rendered or removed in viewWillAppear and viewWillDisappear method respectively. However, since we are hiding / showing the button in viewDidAppear / viewDidDisappear, it's causing momentary lag with respect to tab. – Keya Jun 22 '18 at 04:23
-
SPatel, thanks for the reference, I will check these too. However, initially we started with adding the view as a subview of tab bar itself. But we faced issues of button still visible when we navigate to another screen. – Keya Jun 22 '18 at 04:24
-
embed tabbarviewcontroller in navigation controller, it's work fin for me – SPatel Jun 22 '18 at 04:28
-
you can refer this https://itunes.apple.com/us/app/luxe-radio/id1073120504?mt=8 – SPatel Jun 22 '18 at 04:31
1 Answers
0
Proper way to add button is add it in view of UItabBarController's view instead adding in UIWindow
class DashBoardViewController: UITabBarController {
let button:UIButton = {
let view = UIButton(frame: .zero)
view.backgroundColor = .blue
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
initView()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
button.center = tabBar.center
}
private func initView() {
button.center = tabBar.center
view.addSubview(button)
}
}

SPatel
- 4,768
- 4
- 32
- 51