2010-05-18 79 views
0

我有一個UIPickerView,其中顯示可變數目的組件。在其位指示我有這個-pickerView:withForComponent:在觸摸時擴展PickerViews組件

- (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]這工作得很好,但我怎麼能延長部件的寬度,如果它被觸摸(當然收縮所有其他)?

回答

1

要做到這一點,即使你的選擇器選項的所有文字,你將不得不使用

pickerView:viewForRow:forComponent:reusingView: 

你基本上需要產生UIViews的數組,你的選擇器選項,在留住他們數組。然後,當選中一行時,直接展開該UIView,然後遍歷數組,相應地縮小其他數組。