iosobjective-ciphoneoverlays

Objective-C how to present an action sheet from tab bar that overlaps the current view?


I'd like to add an action sheet that appears when tab bar center item is clicked. like in this example: this is how it shows when center item is clicked

i have added the tab bar from storyboard and its working fine. the hard part of it is how to keep the previous view and overlay the action sheet. thanks in advance.


Solution

  • use this delegate function to intercept tab selection

    for swift 3

    func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        if self.tabBarController.customizableViewControllers.index(of: viewController) == 2 {
           //display action sheet
           return false
        }
        return true
    }
    

    for objective c

    - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    //same logic above
    }