2014-09-27 7 views
0

UIPickerView가 회전 중인지 알 수있는 방법이 있습니까? 전환 중일 때 일부 UI 요소를 비활성화해야합니다.UIPickerView가 회전 중인지 알 수있는 방법이 있습니까?

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

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

어쩌면 pickerView:titleForRow:forComponent:이 코드를 넣을 수있는 좋은 장소가 어쩌면입니다 :

+0

는 http://stackoverflow.com/questions/5304839/determining-if-uipickerwheel-is-scrolling – rmaddy

답변

1

UIPickerViewUIView의 서브 클래스이기 때문에이에 대한 위임 방법은 그러나 당신이 animationKeys 수를 확인할 수 있습니다?

+0

가 작동하지 않습니다를 참조하십시오. didSelectRow 이벤트에 행 번호를 저장하고 selectedRowInComponent와 비교할 것입니다. 그것들이 같지 않으면 회전하고 있습니다. – JVC

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; 

} 
+0

예, 타이머를 사용하면 추한 것입니다. – JVC

관련 문제