2013-01-15 7 views
1

내 iOS 앱에서 버튼이 : 10 분비활성화 버튼

_Button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    UIImage *shareIMG = [UIImage imageNamed:@"button.png"]; 
    [_Button setBackgroundImage:shareIMG forState:UIControlStateNormal]; 
    [_Button setBackgroundImage:[UIImage imageNamed:@"button_active.png"] forState:UIControlStateHighlighted]; 
    [_Button addSubview:titleLabel]; 

    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 3, shareIMG.size.width, shareIMG.size.height)]; 
    [titleLabel setTextAlignment:UITextAlignmentCenter]; 
    [titleLabel setText:@"Button"; 
    [_Button addSubview:titleLabel]; 
    [titleLabel release]; 
    [_Button setFrame:CGRectMake(2 * self.sendPushButton.frame.origin.x + self.sendPushButton.frame.size.width , 380 - liteIndent1 - liteIndent2 + iphone5Fix, shareIMG.size.width, shareIMG.size.height)]; 
    [self addSubview:_Button]; 

가이 버튼을 비활성화 (button_non_active.png)을 만드는 방법을 도와 수 및 취소 클릭 클릭 후? .

-(void)enableButton:(UIButton *)button { 
    [button setBackgroundImage:[UIImage imageNamed:@"button_active.png"] forState:UIControlStateHighlighted]; 
    button.enabled = YES; 
} 

그리고 누르면 발사됩니다 셀렉터 (당신이 당신의 조각에서이 누락 된 것으로 보인다으로 설정 :

+1

이 응용 프로그램은 사망하고 다시 시작하더라도? –

+0

버튼을 클릭 할 때 NSTimer를 사용하거나 비활성화하거나 userInteraction을 false로 설정하고 타이머를 10 분으로 설정하고 NSTimer 함수에서 버튼을 활성화하거나 userInteraction을 TRUE로 설정합니다. –

답변

0

것 같은 클래스의 메소드 만들기를 재 활성화 [_Button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];)

-(void)buttonPressed:(UIButton *)button { 
    //do actual action here 
    [button setBackgroundImage:[UIImage imageNamed:@"button_non_active.png"] forState: UIControlStateHighlighted]; 
    button.enabled = NO; 
    [self performSelector: @selector(enableButton:) withObject: button afterDelay: 600.0]; 
} 
+0

부싱 후 메소드 버튼 사용은 비활성 상태가되지만 지연 후 활성화되지만 이미지가 표시됩니다. 뭐가 잘못 되었 니? 'UIControlStateHighlighted' 대신 –

+0

대신'UIControlStateNormal'을 시도하십시오. – cscott530

+0

그걸 시도했지만 이미지가 가 아니 었습니다. 약간의 정보만으로 구성된 것입니다. –

0

사용`

btn.enabled=NO;` 

    NSTimer * notificationTimer = [NSTimer scheduledTimerWithTimeInterval:10*60.0 target:self selector:@selector(enable) userInfo:nil repeats:No]; 

    -(void)enable 
    { 
    btn.enabled=YES; 
    } 

그냥 지침을 수정합니다. 필요에 따라 반복 예 또는 아니오를 설정하십시오.

5
// disable button 
[_Button setEnabled:NO]; 

// run a selector after 10 minutes 
[_Button performSelector:@selector(onEnableButton:) withObject:_Button afterDelay:(10.0 * 60.0)] 


- (void) onEnableButton:(UIButton *)sender 
{ 
[sender setEnabled:YES]; 
} 
+0

+1 좋은 답변입니다. – Rushi

+0

충돌이 발생하고 버튼이 처음부터 활성화되어 있지 않습니다. –

0

버튼을 클릭 할 때 기능을 호출해야합니다.

- (void)buttonClickedStartTimer 
{ 
    _Button.userInteractionEnabled = FALSE; 
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(stopTimer) userInfo:nil repeats:YES]; 

} 

- (void)stopTimer 
{ 
    _Button.userInteractionEnabled = TRUE; 
    [timer invalidate]; 
    [timer release]; 
} 
0
 
    _Button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [_Button setImage:[UIImage imageNamed:@"button_active.png"] forState:UIControlStateNormal]; 
    [_Button setImage:[UIImage imageNamed:@"button_non_active.png"] forState:UIControlStateDisabled]; 
    [_Button addSubview:titleLabel]; 
    [_Button setEnabled:NO]; 

    int64_t delayInSeconds = 60.0 * 10; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     [_Button setEnabled:YES]; 
    });