触摸时扩展 PickerViews 组件

发布于 2024-09-02 16:49:42 字数 529 浏览 0 评论 0原文

我有一个 UIPickerView,其中要显示的组件数量可变。在它的控制器中,我有这个 -pickerView:withForComponent:

- (CGFloat)pickerView:(UIPickerView *)pv widthForComponent:(NSInteger)component {
    CGFloat f;
    if (component == 0) {
        f = 30;

    } else {
        if ([componentsData count]>2) {
            f = 260.0/([componentsData count]-1);
        } else{
            f = 260.0;
        }
    } 
    return f;
}

如果我调用 [pickerView reloadAllComponents] ,它可以正常工作,但是如果它被触摸(并且当然缩小所有其他的)?

I have a UIPickerView with a variable number of components to display. In its contoller i have this -pickerView:withForComponent:

- (CGFloat)pickerView:(UIPickerView *)pv widthForComponent:(NSInteger)component {
    CGFloat f;
    if (component == 0) {
        f = 30;

    } else {
        if ([componentsData count]>2) {
            f = 260.0/([componentsData count]-1);
        } else{
            f = 260.0;
        }
    } 
    return f;
}

this works fine if I call [pickerView reloadAllComponents], but how could I extend a components width if it is touched (and of course shrink all others)?

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

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

发布评论

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

评论(1

暖心男生 2024-09-09 16:49:42

为此,即使您的选择器选项都是文本,您也必须使用

pickerView:viewForRow:forComponent:reusingView:

您基本上需要为选择器选项生成 UIView 数组,并将它们保留在数组中。然后,当选择一行时,直接展开该 UIView,并迭代数组,相应地收缩其他数组。

To do this, even if your picker options are all text, you'll have to use

pickerView:viewForRow:forComponent:reusingView:

You'll basically need to generate an array of UIViews for your picker options, and retain them in an array. Then, when a row is selected, expand that UIView directly, and iterate through the array, contracting the others accordingly.

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