Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios MBProgessHUD将立即隐藏。如何设置最短放映时间?_Ios_Objective C - Fatal编程技术网

Ios MBProgessHUD将立即隐藏。如何设置最短放映时间?

Ios MBProgessHUD将立即隐藏。如何设置最短放映时间?,ios,objective-c,Ios,Objective C,我想用customView显示MBProgressHUD,显示用户购买的东西。这是我试过的 - (void)showInfoAlert:(int)clues { UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject]; MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES]; hud.cu

我想用customView显示
MBProgressHUD
,显示用户购买的东西。这是我试过的

- (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秒钟。

您要查找的属性是

/**
 * 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;
MBProgressHud
类中

加上

hud.minShowTime = 3.f;
你应该可以走了

编辑:您应该删除对
-showAnimated:whileExecutingBlock:
的调用,因为它在后台队列中调度块:这就是为什么它不会阻止HUD(与其他所有UI组件一样,HUD由主线程控制)。不管怎样,将主线程置于睡眠状态都不是一个好主意,因为这会导致糟糕的用户体验(如果长时间阻止,系统可能会杀死你的应用程序)


您可以用一个简单的
-show:

来替换该调用,这样就不需要睡眠方法了?我想应该不再需要它了。为什么不使用
[hud hide:YES afterDelay:3.0]?我也尝试过这个,但不适合我。