UITableView上的子视图

时间:2014-06-30 18:05:29

标签: ios objective-c uitableview uiview subview

我在表视图控制器中添加了一个子视图。子视图有三个子视图(关闭按钮,用于模糊主视图的工具栏和表视图)。问题是您仍然可以在子视图的底部看到一些主视图。我已尝试使用此框架contentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];初始化子视图,并修复了该问题,但如果我向下滚动父视图的表视图,则无法看到子视图。我该如何解决这个问题?

enter image description here

- (void)showMenu
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;

    UIColor *kfbBlue = [UIColor colorWithRed:8.0/255.0f green:77.0/255.0f blue:139.0/255.0f alpha:1];

    contentView = [[UIView alloc]initWithFrame:self.tableView.bounds];
    contentView.autoresizesSubviews = YES;
    contentView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    contentView.backgroundColor = [UIColor clearColor];

    UIButton *closeMenuButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeMenuButton setFrame:CGRectMake(275, 10, 40, 40)];
    [closeMenuButton setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
    [closeMenuButton addTarget:self action:@selector(closeMenu) forControlEvents:UIControlEventTouchUpInside];

    blurredView = [[UIToolbar alloc]initWithFrame:contentView.bounds];
    [blurredView setBarStyle:UIBarStyleBlack];
    [blurredView setBarTintColor:kfbBlue];

    MenuTableViewController *menu = [[MenuTableViewController alloc]initWithNibName:@"MenuTableViewController" bundle:nil];
    menu.view.frame = CGRectMake(0, 30, screenWidth, screenHeight);
    [self.view addSubview:contentView];
    [contentView addSubview:blurredView];
    [self addChildViewController:menu];
    [contentView addSubview:menu.view];
    [contentView addSubview:closeMenuButton];
    self.navigationController.navigationBarHidden = YES;
    self.tableView.scrollEnabled = NO;
}

0 个答案:

没有答案