Ios MBProgessHUD将立即隐藏。如何设置最短放映时间?
我想用customView显示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
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]代码>?我也尝试过这个,但不适合我。