Проблема с кнопкой UITabBar, кнопка TabBar становится неактивной

Я создаю представление с UINavigationBar и UITabBar. Я добавил кнопку на панель вкладок, при нажатии кнопки я скрываю панель вкладок и показываю панель инструментов внизу. Мой код написан как для текущей, так и для предыдущих версий iOS. Я использую этот код self.edgesForExtendedLayout = UIRectEdgeNone; для iOS7, это мой код:

- (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];

}

Моя проблема заключается в том, что при нажатии кнопки вызываются методы hideTabBar и loadToolBar. Все работает нормально, за исключением того, что моя кнопка теперь не нажимается на панели инструментов. Помогите мне, пожалуйста.


person Mayank Purwar    schedule 08.10.2013    source источник
comment
кстати, пробовали ли вы SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@7.0)   -  person DogCoffee    schedule 08.10.2013
comment
Я использую это. if ([[[UIDevice currentDevice] systemVersion] intValue] ›= 7.0) { self.edgesForExtendedLayout = UIRectEdgeNone; }   -  person Mayank Purwar    schedule 08.10.2013
comment
Да, я знаю, почему я показал вам то, что я думаю, что это более чистый способ сделать то же самое. Что касается вашего вопроса, можете ли вы получить NSLog по нажатию кнопки?   -  person DogCoffee    schedule 08.10.2013
comment
Нет. Кнопка не кликабельна. Если я установлю рамку панели инструментов немного выше, то она кликабельна.   -  person Mayank Purwar    schedule 08.10.2013
comment
Можем ли мы получить ссылку для скачивания вашего кода?   -  person Jageen    schedule 08.10.2013


Ответы (1)


у меня была аналогичная проблема, если ваш контроллер просмотра не является корневым контроллером представления, iOS не получает рамку просмотра.

Добавьте эту строку в свой контроллер просмотра в viewdidload,

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

Надеюсь, поможет

person Mihriban Minaz    schedule 22.08.2014