在没有启用UserInteraction的情况下按下Scrollview中的按钮

时间:2017-07-25 15:01:45

标签: ios objective-c iphone uitableview uiscrollview

我使用带有页眉和页脚的UITableView,整个TableView内部都有水平的UIScrollViews。我将它用作锁定标题功能,就像在Excel中一样。

UITcrollView在UITableview标题和UITableView页脚中禁用了UserInteraction,只在主体滚动时滚动。

在我的标题中,我现在有一个位于UIScrollViews ContentView中的按钮,我需要能够与它进行交互,但这并不是......过去有没有人碰到这个?

许多不需要的代码已被省略......

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UITableViewHeaderFooterView  *viewHeader;

    UIButton *flow; 

    viewHeader = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(0, 1, self.tableview.frame.size.width, 48)];

    UIView *thisContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, contentWidth, 48)];

    flow = [[UIButton alloc] initWithFrame:CGRectMake( flowRate.frame.origin.x + flowRate.frame.size.width + 5, 14, colWidth1,  20)];
    [flow.imageView setImage:[UIImage imageNamed:@"ic_flow"]];
    flow.imageView.contentMode = UIViewContentModeScaleAspectFit;
    [flow setContentMode:UIViewContentModeScaleAspectFit];
    [UniversalMethods tintImageviewInButton:flow withColor:BRIGHT_BLUE];

    [flow addTarget:self action:@selector(showSortingAlert:) forControlEvents:UIControlEventTouchUpInside];

    [thisContentView addSubview:flow];

    [thisScrollview addSubview:thisContentView];
    thisScrollview.contentSize = thisContentView.frame.size;
    thisScrollview.tag = scrollTag;
    [thisScrollview setUserInteractionEnabled:false];

    [viewHeader addSubview:thisScrollview];

    return viewHeader;
}

1 个答案:

答案 0 :(得分:1)

在视图上禁用userInteraction时,它还会阻止将触摸事件传递给其子视图。您需要在滚动视图上启用userInteraction才能点按该按钮。您可以将isScrollEnabled设置为false,以防止滚动视图滚动。

相关问题