有没有办法判断UIPickerView是否正在旋转?

时间:2014-09-27 02:35:18

标签: ios objective-c uipickerview

有没有办法判断UIPickerView是否正在旋转? 我需要在转换过程中禁用一些UI元素。

3 个答案:

答案 0 :(得分:1)

没有委托方法,但是您可以检查animationKeys计数,因为UIPickerViewUIView的子类:

BOOL isSpinning = myPickerView.layer.animationKeys.count > 0;

if(isSpinning){
   NSLog(@"disable");
}else{
   NSLog(@"enable");
}

也许pickerView:titleForRow:forComponent:可能是放置此代码的好地方?

答案 1 :(得分:1)

我通过在didSelectRow中保存行号并将其与selectedRowInComponent中的行进行比较来解决此问题。

-(BOOL) isCardPickerSpinning{
return (lastCardPickerRow != [cardPicker selectedRowInComponent:0]);}

我还创建了一个布尔值,用于在微调器运动时调用方法。

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
  inComponent:(NSInteger)component
{
 lastCardPickerRow = row;
 pickerInMotion = NO;
 //update UI code goes here
 eventSwitch.enabled = YES;
}

 -(void)pickerViewMotionStart
{
    //disable my UI
    eventSwitch.enabled = NO;
}

- (UIView *)pickerView:(UIPickerView *)pickerView
        viewForRow:(NSInteger)row
      forComponent:(NSInteger)component
       reusingView:(UIView *)view {

UILabel *pickerLabel = (UILabel *)view;
 if (pickerLabel == nil) {
    CGRect frame = CGRectMake(0.0, 0.0, 200, 32);
    pickerLabel = [[UILabel alloc] initWithFrame:frame];
    pickerLabel.textAlignment=NSTextAlignmentLeft;
 }
 if (!pickerInMotion)
 {
    pickerInMotion = YES;
    [self pickerViewMotionStart];
 }
 pickerLabel.text = @"SomeString";
 return pickerLabel;

}

答案 2 :(得分:0)

Swift 4.2中的JVC解决方案

1。创建2个变量

<% @task.errors.each do |elem| %>
  <div class="input">
    ...stuff...
  </div>    
<% end %>

2。将行号保存在$(document).ready(function() { $('.input').addClass('danger'); }) 中,并将其与var lastPickedRow = 0 var pickerInMotion: Bool = false 中的行进行比较。

didSelectRow

3。创建运动开始时调用的方法

selectedRowInComponent

4。在var isPickerSpinning: Bool { return lastPickedRow != pickerView.selectedRow(inComponent: 0) }

func pickerViewMotionStart(){
    //Do something when motion started
    button.alpha = 0
}

5。在didSelectRow

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

    lastPickedRow = row
    pickerInMotion = false
    //Do something when motion ended
    button.alpha = 1
}