Issue with UITabBar button, TabBar button becomes un clickable
Asked Answered
D

1

6

I am creating a view with UINavigationBar and UITabBar. I have added a button on tab bar, on button click, i am hiding tab bar and show tool bar at the bottom. My code is written for current as well as previous iOS versions. I am using this code self.edgesForExtendedLayout = UIRectEdgeNone; for iOS7 this is my code :

- (void)hideTabBar {
    UITabBar *tabBar = self.tabBarController.tabBar;
    UIView *parent = tabBar.superview; // UILayoutContainerView
    UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView
    UIView *window = parent.superview;enter code here
    [UIView animateWithDuration:0.5
                     animations:^{
                         CGRect tabFrame = tabBar.frame;
                         tabFrame.origin.y = CGRectGetMaxY(window.bounds);
                         tabBar.frame = tabFrame;

//                         CGRect contentFrame = content.frame;
//                         contentFrame.size.height -= tabFrame.size.height;
                         content.frame = window.bounds;
                     }];

     if ([[[UIDevice currentDevice] systemVersion] intValue] < 7.0)
     {
    CGRect frame = tbl_AllFiles.frame;
    frame.size.height -=tabBar.frame.size.height;
    tbl_AllFiles.frame = frame;
     }

}

- (void)showTabBar {
    UITabBar *tabBar = self.tabBarController.tabBar;
    UIView *parent = tabBar.superview; // UILayoutContainerView
    UIView *content = [parent.subviews objectAtIndex:0];  // UITransitionView
    UIView *window = parent.superview;

    if ([[[UIDevice currentDevice] systemVersion] intValue] < 7.0)
    {
    CGRect frame = tbl_AllFiles.frame;
    frame.size.height +=tabBar.frame.size.height;
    tbl_AllFiles.frame = frame;
    }

    [UIView animateWithDuration:0.5
                     animations:^{
                         CGRect tabFrame = tabBar.frame;
                         tabFrame.origin.y = CGRectGetMaxY(window.bounds) - CGRectGetHeight(tabBar.frame);
                         tabBar.frame = tabFrame;

                         CGRect contentFrame = content.frame;
                         contentFrame.size.height -= tabFrame.size.height;
                         content.frame = contentFrame;
                     }];
}
- (void)loadToolBar {

    toolbar = [UIToolbar new];
    toolbar.barStyle = UIBarStyleBlackTranslucent;    


    moveButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [moveButton setFrame:CGRectMake(10, 10, 120, 25)];
    [moveButton setBackgroundColor:[UIColor redColor]];
    [moveButton setTitle:@"Move" forState:UIControlStateNormal];
    [moveButton addTarget:self action:@selector(moveFile_Folder:) forControlEvents:UIControlEventTouchUpInside];

    UIBarButtonItem *moveItem = [[[UIBarButtonItem alloc] initWithCustomView:moveButton] autorelease];
    moveItem.style = UIBarButtonItemStyleBordered;
    NSArray *items = [NSArray arrayWithObjects:moveItem, nil];
    toolbar.items = items;

    [toolbar sizeToFit];
    CGFloat toolbarHeight = [toolbar frame].size.height;
    CGRect mainViewBounds = self.view.bounds;

    if ([[[UIDevice currentDevice] systemVersion] intValue] < 7.0)
    {
        [toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
                                     CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds) - (toolbarHeight),
                                     CGRectGetWidth(mainViewBounds),
                                     toolbarHeight)];
    }
    else
    {
        [toolbar setFrame:CGRectMake(CGRectGetMinX(mainViewBounds),
                                 CGRectGetMinY(mainViewBounds) + CGRectGetHeight(mainViewBounds),
                                 CGRectGetWidth(mainViewBounds),
                                 toolbarHeight)];
    }

    [self.view addSubview:toolbar];
    [toolbar bringSubviewToFront:self.view];

}

My issue is on button clicked hideTabBar and loadToolBar methods are called. Everything is working fine, except my button is un-clickable now on toolbar. Please help me.

Debussy answered 8/10, 2013 at 4:41 Comment(5)
on a side note, have you tried SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")Heidt
I am using that. if ([[[UIDevice currentDevice] systemVersion] intValue] >= 7.0) { self.edgesForExtendedLayout = UIRectEdgeNone; }Debussy
Yeah, I know that why I showed you what I think its a cleaner method for doing the same thing. In regard to your question, can you get a NSLog from your button click?Heidt
No. Button is not clickable.If I set the frame of tool bar some above, then its clickable.Debussy
Can we have downloadable link for your code ?Trestle
P
0

i had a similar issue if your viewcontroller is not the root view controller iOS doesn't get the view frame.

Add this line to your viewcontroller in viewdidload,

self.view.frame = [UIScreen mainScreen].bounds;

hope it helps

Phonemics answered 22/8, 2014 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.