xcode MBProgressHUD 或 DSActivityView - 点击取消
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5449917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MBProgressHUD or DSActivityView - tap to cancel
提问by woopsicle
I have come across both MBProgressHUD and DSActivityView to show the black rounded corner "Loading" type overlays on an iPhone app.
我遇到了 MBProgressHUD 和 DSActivityView 以在 iPhone 应用程序上显示黑色圆角“加载”类型覆盖。
I am just wondering if anyone knows how to extend either of these to detect a tap of the overlay, so that the action can be cancelled.
我只是想知道是否有人知道如何扩展其中任何一个来检测覆盖层的点击,以便可以取消操作。
I have seen at least one app out there which has the "Loading" indicator. But with the text "Tap to cancel".
我已经看到至少有一个应用程序具有“正在加载”指示器。但是带有“点击取消”的文字。
Thanks!
谢谢!
回答by user1032657
- (void)showHUDWithCancel:(NSString *)aMessage {
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
self.HUD.labelText = aMessage;
self.HUD.detailsLabelText = @"Tap to cancel";
[self.HUD addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hudWasCancelled)]];
}
- (void)hudWasCancelled {
[self.HUD hide:YES];
}
回答by lxt
The easiest way to do this is to add a gesture recogniser (for a single tap) to the relevant view (in the case of MBProgressHUD, this can be the class itself, since MBProgressHUD
is a subclass of UIView
). Upon detecting the tap, you can trigger the dismiss method ([MBProgress HUD hide]
).
最简单的方法是将手势识别器(用于单击)添加到相关视图(在 MBProgressHUD 的情况下,这可以是类本身,因为它MBProgressHUD
是 的子类UIView
)。检测到点击后,您可以触发解除方法 ( [MBProgress HUD hide]
)。
You'll probably also want to trigger a NSNotification of some sort for your app to pick up on, because presumably in addition to removing the loading view itself you'll also want to cancel and clean up the operation you were performing during the load.
您可能还想触发某种 NSNotification 以供您的应用程序接收,因为大概除了删除加载视图本身之外,您还需要取消和清理您在加载期间执行的操作。