触摸外部时隐藏 UITableViewController 中的 UIPickerView

发布于 2024-11-14 15:32:25 字数 252 浏览 2 评论 0原文

现在我的 UITableViewController 中有 2 个不同的 UIPickerView。我仅在点击表格中的某些单元格时显示它们。我想做的是每当我触摸拾取器外部时隐藏拾取器。是否有委托方法或类似的方法来实现此目的?我更喜欢将控制器保留为 UITableViewController 而不是简单的 UIViewController,因为我在其中一个单元格中有一个 textView,并且在键盘显示后滚动在 UIViewController 中有点太多了。

提前致谢。

Right now I have 2 different UIPickerView in side my UITableViewController. I only show them upon tapping of certain cells in the table. What I'm trying to do is to hide the pickers whenever I touch outside the pickers. Is there a delegate method or something similar to achieve this? I prefer to keep my controller as a UITableViewController instead of a simple UIViewController since I have a textView in one of the cells and scrolling after the keyboard shows is just a bit too much in a UIViewController.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

佞臣 2024-11-21 15:32:25

可能的解决方案之一是,当点击特定单元格并处理选择器(以显示选择器)时,您可以在表格视图上插入一个名为“MASK View”的视图。 (框架为 self.tableview.frame - yourPicker.frame.size.height )。现在,当您单击此视图时,您可以按如下方式处理它

-(void)showMaskView{
    if (!viewMaskView) {
        CGRect viewRect = CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.height - yourPicker.frame.size.height);
        viewMaskView = [[MaskView alloc] initWithFrame:viewRect];
        viewMaskView.delegate = self;
    }   
    [self.view addSubview:viewMaskView];
    [self.view bringSubviewToFront:viewMaskView];
}

-(void)removeMaskView{
    if (viewMaskView) {
        [viewMaskView removeFromSuperview];
    }
    //Remove the Picker
}

在 MaskView 类中,您可以按如下方式处理触摸,

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    if(self.delegate && [self.delegate respondsToSelector:@selector(removeMaskView)])
        [self.delegate removeMaskView];
}

您可以在图像中的选取器上看到彩色蒙版视图。当点击时,它会删除选择器。
在此处输入图像描述

One of the Possible solutions is that when a particular cell is tapped and you handle picker (to present the picker), you can insert a view called as MASK View over the tableview. (with Frame as self.tableview.frame - yourPicker.frame.size.height ). Now when ever you get any click on this view you can handle it as follows

-(void)showMaskView{
    if (!viewMaskView) {
        CGRect viewRect = CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.height - yourPicker.frame.size.height);
        viewMaskView = [[MaskView alloc] initWithFrame:viewRect];
        viewMaskView.delegate = self;
    }   
    [self.view addSubview:viewMaskView];
    [self.view bringSubviewToFront:viewMaskView];
}

-(void)removeMaskView{
    if (viewMaskView) {
        [viewMaskView removeFromSuperview];
    }
    //Remove the Picker
}

In the MaskView class you can handle the touch as follows

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    if(self.delegate && [self.delegate respondsToSelector:@selector(removeMaskView)])
        [self.delegate removeMaskView];
}

you can see the colored mask view over the Picker in the image. When tapped it removes picker.
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文