我在下面有一些源代码,这些源代码将重现此。在HUD有机会出现之前,请致电showWithStatus
并解散,导致控件未显示下一次showWithStatus
。有人知道任何解决方法吗?
// Commenting these will show SVProgressHUD
[SVProgressHUD showWithStatus:@"Loading..."];
[SVProgressHUD dismiss];
// Comment above to show SVProgressHUD
[SVProgressHUD showWithStatus:@"Loading..."];
[self performSelector:@selector(dismissHUD) withObject:nil afterDelay:5.0f];
编辑:我在这里有一些源代码,可以重现此。
我通过为第二个HUD显示而围绕它进行了工作:
[self performSelector:@selector(showHud) withObject:nil afterDelay:0.1];
我已经解决了问题:
1。添加属性
@property (nonatomic, readonly, getter = isDismissing) BOOL dismissing;
2. ADD flag
- (void)dismissWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay {
_dismissing = YES;
...
void (^completionBlock)(void) = ^{
...
_dismissing = NO;
};
...
}
重命名函数
- (void)showImage:(UIImage)image status:(NSString)status duration:(NSTimeInterval)duration
to with name
- (void)showImageSS:(UIImage)image status:(NSString)status duration:(NSTimeInterval)duration
3.ADD延迟
- (void)showImage:(UIImage*)image status:(NSString*)status duration:(NSTimeInterval)duration
{
if(self.isDismissing){
__weak SVProgressHUD *weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * SVProgressHUDDefaultAnimationDuration),dispatch_get_main_queue(), ^{
[weakSelf showImageSS:image status:status duration:duration];
});
}else{
[self showImageSS:image status:status duration:duration];
}
}
和
- (void)showImageSS:(UIImage*)image status:(NSString*)status duration:(NSTimeInterval)duration
{
// this is orginal function - (void)showImage:(UIImage)image status:(NSString)status duration:(NSTimeInterval)duration code block
}
finsh谢谢大家