2012-01-13 3 views
1

버튼을 눌렀을 때 0-10 초 사이의 임의의 시간 동안 버튼을 사용하지 않으면 버튼이 활성화됩니다 다시. 그러나 버튼이 비활성화되어있는 동안 사용자가 클릭하면 클릭 대기 상태가되어 버튼이 활성화되고 클릭이 처리됩니다. 어떻게하면 사용자 클릭을 비활성화하고 대기열에 넣지 않을까요?대물 렌즈 버튼 대기열 사용자 터치 업 해제

-(void)buttonPressed{ 
    NSLog(@"Button pressed!"); 
    button.userInteractionEnabled=false; 
    sleep(rand()%10); 
    [email protected]"button is enabled!"; 
    button.userInteractionEnabled = true; 
} 

답변

1

나는 당신이 UIControl에서 파생되는 버튼을 사용하고 있으리라 믿고있어 (UIButton을?). 기존 enabled 속성을 활용할 수 있습니다. 속성을 NO으로 설정하면 모든 터치 이벤트가 무시됩니다. UIControl에 대한 정보는 this link을 참조하십시오.

또 다른 예는 사용자의 sleep() 기능입니다. 나는 그 기능에 익숙하지 않다. 그러나 이 주 스레드를 차단할 수있다. 주의하세요. 대신 NSTimer을 사용해야합니다. 각 간격 후에 토글 효과를 위해 button.enabled = !button.enabled을 수행 할 수 있습니다. ,

+0

감사 것 나는 NSTimer를 시도 할 것이다! – Denis

2

당신은 절전 기능을

-(void) sleepMethood 
{ 
sleep(rand()%10); 
} 

전화 methood에

[self performSelector:@selector(sleepMethood) withObject:nil afterDelay:0.5]; 

FUNC 슬립() 대신이를 사용하거나 다른 해결 방법은

-(void)buttonPressed{ 
NSLog(@"Button pressed!"); 
button.alpha=0.7; 
button.enabled=NO; 
[self performSelector:@selector(BtnEnblMethood) withObject:nil afterDelay:(rand()%10)]; 
[email protected]"button is enabled!"; 
} 

-(BtnEnblMethood) 
{ 
button.alpha=1; 
button.enabled=YES; 
} 
관련 문제