1

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.

required ui

7
  • 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 Commented Jun 22, 2018 at 4:13
  • I think it's not proper way, you should add button in view of tabbarcontroller Commented Jun 22, 2018 at 4:14
  • stackoverflow.com/a/48293806/6630644 Commented Jun 22, 2018 at 4: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. Commented Jun 22, 2018 at 4: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. Commented Jun 22, 2018 at 4:24

1 Answer 1

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)
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.