加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xcode – UITabBar按钮问题,TabBar按钮变为无法点击

发布时间:2020-12-14 19:36:43 所属栏目:百科 来源:网络整理
导读:我正在使用UINavigationBar和UITabBar创建一个视图.我在标签栏上添加了一个按钮,点击按钮,我隐藏标签栏并在底部显示工具栏.我的代码是针对当前以及之前的iOS版本编写的.我正在使用此代码self.edgesForExtendedLayout = UIRectEdgeNone;对于iOS7,这是我的代码
我正在使用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),toolbarHeight)];
    }

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

}

我的问题是按钮单击hideTabBar和loadToolBar方法被调用.一切都运行正常,除了我的按钮现在在工具栏上无法点击.
请帮我.

解决方法

如果你的viewcontroller不是根视图控制器iOS没有获取视图框,我有一个类似的问题.

在viewdidload中将此行添加到viewcontroller,

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

希望能帮助到你

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读