2013-10-08 7 views
6

Ich erstelle eine Ansicht mit UINavigationBar und UITabBar. Ich habe eine Schaltfläche in der Tableiste hinzugefügt, beim Klicken auf die Schaltfläche, ich habe die Tableiste ausgeblendet und die Symbolleiste unten angezeigt. Mein Code ist für aktuelle sowie frühere iOS-Versionen geschrieben. Ich verwende diesen Code self.edgesForExtendedLayout = UIRectEdgeNone; für iOS7 dies ist mein Code:Problem mit der UITabBar-Schaltfläche, TabBar-Schaltfläche wird nicht anklickbar

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

} 

Mein Problem auf Schaltfläche geklickt HideTabBar und loadToolBar Methoden aufgerufen werden. Alles funktioniert einwandfrei, außer dass meine Schaltfläche nicht mehr auf der Symbolleiste klickt. Bitte helfen Sie mir.

+0

auf einer Seite zur Kenntnis hilft, haben Sie SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO versucht (@ "7.0") – DogCoffee

+1

ich verwende. if ([[[UIDevice currentDevice] systemVersion] intValue]> = 7.0) { selb.edgesForExtendedLayout = UIRectEdgeNone; } –

+0

Ja, ich weiß, warum ich Ihnen gezeigt habe, was ich denke, es ist eine sauberere Methode, um das Gleiche zu tun. In Bezug auf Ihre Frage, können Sie einen NSLog von Ihrem Knopf klicken? – DogCoffee

Antwort

0

Ich hatte ein ähnliches Problem, wenn Ihr Viewcontroller nicht der Root-View-Controller ist, der iOS den View-Frame nicht bekommt.

diese Zeile in die Viewcontroller in viewDidLoad hinzufügen,

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

hoffen, dass es