Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a UIButton as a subview to a UITabBar

I am trying to implement a hideable UITabBar in my app. I've set up all the animations, and they work very well. I'm just having an issue getting my UIButton "pull-tab" to show the tab bar. It is not responding to the touch event UIControlEventTouchUpInside. I add the pull-tab to the UITabBar in the UITabBarController:

- (void)viewDidLoad
{
    [super viewDidLoad];
//Add pull
    pullButton = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *image = [UIImage imageNamed:@"TabBarPull.png"];
    pullButton.frame = CGRectMake(self.tabBar.frame.size.width - image.size.width, -image.size.height + 3, image.size.width, image.size.height);
    [pullButton setImage:image forState:UIControlStateNormal];
    [pullButton addTarget:self action:@selector(pullBarTapped:) forControlEvents:UIControlEventTouchUpInside];
    pullButton.userInteractionEnabled = YES;
    [self.tabBar addSubview:pullButton];
}

Here is what the tab bar looks like open and closed:

TabBar not hiddenTabBar Hidden

Edit: I've determined that the problem is because the button falls outside the UITabBar's frame. Looks like I'm going to have to put the button outside of the UITabBar... Animation nightmare.

like image 931
Brandon Mcq Avatar asked Jul 21 '12 01:07

Brandon Mcq


1 Answers

You can still add the UIButton to the UITabBarController's main view, not in the UITabBar though.... [myUITabBarController.view addSubview:pullButton]

like image 119
KDaker Avatar answered Nov 09 '22 03:11

KDaker