2013-10-08 15 views
6

Sto creando una vista con e UITabBar. Ho aggiunto un pulsante sulla barra delle schede, sul pulsante clic, sto nascondendo la barra delle schede e mostra la barra degli strumenti in basso. Il mio codice è scritto per versioni attuali e precedenti di iOS. Sto usando questo codice self.edgesForExtendedLayout = UIRectEdgeNone; per iOS7 questo è il mio codice:Problema con il pulsante UITabBar, il pulsante TabBar diventa non selezionabile

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

} 

Il mio problema è sul pulsante cliccato metodi hideTabBar e loadToolBar sono chiamati. Tutto funziona bene, tranne il mio pulsante è disattivabile ora sulla barra degli strumenti. Per favore aiutatemi.

+0

su un lato nota, hai provato SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO (@ "7.0") – DogCoffee

+1

Sto usando questo. if ([[[UIDevice currentDevice] systemVersion] intValue]> = 7.0) { self.edgesForExtendedLayout = UIRectEdgeNone; } –

+0

Sì, lo so perché ti ho mostrato quello che penso sia un metodo più pulito per fare la stessa cosa. Per quanto riguarda la tua domanda, puoi ottenere un NSLog dal clic del tuo pulsante? – DogCoffee

risposta

0

Ho riscontrato un problema simile se il viewcontroller non è il controller di visualizzazione radice iOS non ottiene la cornice di visualizzazione.

aggiungere questa linea al tuo viewcontroller in viewDidLoad,

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

spero che aiuta

Problemi correlati