ASGlobalOverlay 是一个单例弹出控制器,可以在您的应用程序顶部显示警告、滑动菜单和正在工作的指示器。它易于实现,具有现代的外观和感觉。
查看示例应用程序的 GIF,或通过运行 pod try ASGlobalOverlay
来亲自尝试。
使用 CocoaPods 安装
pod 'ASGlobalOverlay'
从您的应用程序代理中调用设置助手
#import <ASGlobalOverlay/ASGlobalOverlay.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
[ASGlobalOverlay setupGlobalOverlay];
return YES;
}
就这样!您已经开始了。
ASGlobalOverlay
的典型用法如下
- (void)showAlert{
ASUserOption * add = [ASUserOption userOptionWithTitle:@"Add" actionBlock:^{NSLog(@"'Add' pressed]");}];
ASUserOption * cancel = [ASUserOption cancelUserOptionWithTitle:@"Cancel" actionBlock:^{NSLog(@"'Cancel' pressed");}];
[ASGlobalOverlay showAlertWithTitle:@"Add Friend" message:@"Are you sure you want add this friend?" userOptions:@[add, cancel]];
}
- (void)showSlideUpMenu{
ASUserOption * delete = [ASUserOption destructiveUserOptionWithTitle:@"Delete" actionBlock:^{NSLog(@"'Delete' pressed");}];
ASUserOption * cancel = [ASUserOption cancelUserOptionWithTitle:@"Cancel" actionBlock:^{NSLog(@"'Cancel' pressed");}];
[ASGlobalOverlay showSlideUpMenuWithPrompt:@"Are you sure you want to delete this post?" userOptions:@[delete, cancel]];
}
- (void)showWorkingIndicator{
[ASGlobalOverlay showWorkingIndicatorWithDescription:@"Loading"];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// some background task
dispatch_async(dispatch_get_main_queue(), ^{
[ASGlobalOverlay dismissWorkingIndicator];
});
});
}
查看 ASGlobalOverlay
头文件和 ASUserOption
头文件获取更多信息和使用方便的辅助方法。
请阅读以下部分以了解重要实现细节。
- (void)customConfigurations{
ASConfiguration * configuration = [ASConfiguration new];
configuration.backgroundColor = yourColor;
configuration.titleColor = yourColor;
configuration.bodyColor = yourColor;
configuration.workingSpinnerColor = yourColor;
configuration.separatorLineColor = yourColor;
configuration.buttonTitleColorNormal = yourColor;
configuration.buttonTitleColorCancel = yourColor;
configuration.buttonTitleColorDestructive = yourColor;
configuration.titleFont = [UIFont fontWithName:@"Courier-Bold" size:17.0f];
configuration.bodyFont = [UIFont fontWithName:@"Courier" size:14.0f];
configuration.buttonTitleFont = [UIFont fontWithName:@"Courier" size:14.0f];
[configuration makeCurrentConfiguration];
}
// be sure to read the ASConfiguration header!
// There are useful helper methods, including configuration presets and support for dynamic fonts.
如果您想在可见的弹出和新的弹出之间平滑过渡,只需为新弹出调用 show 方法。 ASGlobalOverlay
将平滑地过渡第一个弹出。
ASGlobalOverlay
不会覆盖键盘(或禁用键盘)。然而,它可以为您隐藏/显示键盘(以便用户在弹出显示时不会输入任何内容)。请查看示例应用程序或 ASGlobalOverlay
头文件获取详细信息。
应仅在主线程上调用显示或隐藏视图的 ASGlobalOverlay
方法。
不推荐您同时使用 ASGlobalOverlay
和 SVProgressHUD
(请参见下面的 '致谢' 获取详细信息)。
ASGlobalOverlay
为向用户显示弹出提供了一种统一的方式。
计划中的功能可能会更改。
ASGlobalOverlay 在 MIT 授权下可用。有关更多信息,请参阅 LICENSE 文件。
ASGlobalOverlay
由 Amit Sharma 编写和维护。
ASGlobalOverlay
的高级架构基于 SVProgressHUD 的代码。SVProgressHUD 是一个出色的库,其开发者应得到大量赞誉。
由于 ASGlobalOverlay 和 SVProgressHUD 使用类似的代码在视图层次结构中定位,因此不建议您同时使用它们。