2014-03-05 1 views
1

사용자 구매 항목을 표시하려면 customView로 MBProgressHUD을 표시하고 싶습니다. 여기 내가 시도한 것MBProgessHUD가 즉시 숨겨집니다. 최소 쇼 시간을 설정하는 방법?

- (void)showInfoAlert:(int)clues { 

    UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject]; 
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES]; 
    hud.customView = [[[UIImageView alloc] initWithImage: 
         [UIImage imageNamed:@"tick.png"]] autorelease]; 
    hud.mode = MBProgressHUDModeCustomView; 
    hud.dimBackground = YES; 
    NSString* msg = (clues == 1) ? @"1 Clue added to yor account." : [NSString stringWithFormat:@"%d Clues added to yor account.", clues]; 
    hud.labelText = msg; 
    [hud showAnimated:YES whileExecutingBlock:^(void){ 

     [NSThread sleepForTimeInterval:3]; 
    }]; 
} 

hud가 매우 짧은 시간 동안 표시되고 즉시 숨겨집니다. 나는 그것이 가장 빠른 3 초 동안 나타나기를 바란다.

+0

왜 사용'[3.0 : YES afterDelay HUD 숨기기]와 그 호출을 대체 할 수있다? – KudoCC

+0

나는 이것 또한 시도했지만 나를 위해 일하지 않습니다. – Blios

답변

3

당신이 찾고있는 속성은 MBProgressHud 클래스에서

/** 
* The minimum time (in seconds) that the HUD is shown. 
* This avoids the problem of the HUD being shown and than instantly hidden. 
* Defaults to 0 (no minimum show time). 
*/ 
@property (assign) float minShowTime; 

입니다.

그냥

hud.minShowTime = 3.f; 

를 추가하고 당신이 가서 잘되어야합니다.

편집 :이 배경 큐에 블록을 전달하기 때문에 당신은 -showAnimated:whileExecutingBlock:에 전화를 제거해야합니다 : 그것은 (다른 모든 UI 구성 요소처럼 메인 쓰레드에 의해 제어되는) 당신의 HUD를 차단하지 않습니다 그 이유는 . 어쨌든 주 스레드를 잠자기 상태로 두는 것은 좋은 생각이 아니 었습니다. 사용자 경험이 나빠질 수 있기 때문입니다 (너무 오랫동안 차단 된 상태로 유지하는 경우 앱을 죽일 수도 있음). `;

당신은 단순한 -show:

+0

수면 방법이 필요하지 않으십니까? – Blios

+0

더 이상 필요하지 않아야한다고 생각합니다. –

+0

(자세한 내용은 답변을 업데이트했습니다.) –

관련 문제