我在我的应用中使用MBProgressHUD,以便在应用等待网络时让用户更清楚。
我的应用程序充斥着对MBProgressHUD的调用。
示例:
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[User findBy:@{@"email": email} success:^(NSDictionary *user) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
因此,每个网络调用都包含在MBprogress节目中,然后隐藏。必须有一个更清洁的方式。
我想在全球范围内这样做,以便当有网络活动时,HUD会亮起,当它停止时,HUD会关闭。
如何让HUD模仿iPhone网络活动指标正在做什么?
我没有看到任何API。
注意:我正在使用AFNetworking 2.0
答案 0 :(得分:1)
应该很简单。
AFnetworking
请求的实施中。使用应用程序窗口显示hud,以便您可以从AFNetworking
课程中展示它。只需将这两种方法添加到您的班级 -
+ (MBProgressHUD *)showNetworkHUDWithTitle:(NSString *)title {
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
[MBProgressHUD hideAllHUDsForView:window animated:YES];
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:window animated:YES];
hud.labelText = title;
return hud;
}
+ (void)dismissNetworkHUD {
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
[MBProgressHUD hideHUDForView:window animated:YES];
}
你也可以检查一下MBProgressHUD“show while”方法 -
- (id)showAnimated:(BOOL)动画whileExecutingBlock :( dispatch_block_t)阻止;
- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(MBProgressHUDCompletionBlock)completion;
- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue;
- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue
completionBlock:(MBProgressHUDCompletionBlock)completion;
这样,hud将在执行结束时消失。