// // ToastManager.m // Unity-iPhone // // Created by zhl on 2022/12/7. // #import "ToastManager.h" #import #import #import "UIView+Toast.h" @implementation ToastManager + (void)showToastWithMessage:(NSString*)message { if (message == nil) { message = @""; } //tip UIWindow * window = [[UIApplication sharedApplication] keyWindow]; [window makeToast:message duration:2 position:CSToastPositionCenter]; } + (void) showToastWithImage:(NSString*)message image:(UIImage *)image { UIWindow * window = [[UIApplication sharedApplication] keyWindow]; CSToastStyle *style = [[CSToastStyle alloc] initWithDefaultStyle]; style.backgroundColor = [UIColor colorWithRed: 0.0/255.0 green: 0.0/255.0 blue: 0.0/255.0 alpha: 100.0/255.0]; style.horizontalPadding = 0; style.verticalPadding = 0; style.imageSize = image.size; style.fullScreen = YES; style.shadowRadius = .0; [window makeToast:@"" duration:0 position: CSToastPositionCenter title: @"" image:image style:style completion:nil]; } + (UIViewController*)getTopViewController { return [self currentTopViewController]; } #pragma mark- Get TOP VC + (UIViewController*)topRootController { UIViewController *topController = [[UIApplication sharedApplication].delegate.window rootViewController]; // Getting topMost ViewController while ([topController presentedViewController]) topController = [topController presentedViewController]; // Returning topMost ViewController return topController; } + (UIViewController*)presentedWithController:(UIViewController*)vc { while ([vc presentedViewController]) vc = vc.presentedViewController; return vc; } + (UIViewController*)currentTopViewController { UIViewController *currentViewController = [self topRootController]; if ([currentViewController isKindOfClass:[UITabBarController class]] && ((UITabBarController*)currentViewController).selectedViewController != nil ) { currentViewController = ((UITabBarController*)currentViewController).selectedViewController; } currentViewController = [self presentedWithController:currentViewController]; while ([currentViewController isKindOfClass:[UINavigationController class]] && [(UINavigationController*)currentViewController topViewController]) { currentViewController = [(UINavigationController*)currentViewController topViewController]; currentViewController = [self presentedWithController:currentViewController]; } currentViewController = [self presentedWithController:currentViewController]; return currentViewController; } @end