react-native-navigation的迁移库

RNNOverlayManager.m 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #import "RNNOverlayManager.h"
  2. #import "RNNOverlayWindow.h"
  3. @implementation RNNOverlayManager
  4. - (instancetype)init {
  5. self = [super init];
  6. _overlayWindows = [[NSMutableArray alloc] init];
  7. return self;
  8. }
  9. #pragma mark - public
  10. - (void)showOverlay:(UIViewController *)viewController {
  11. UIWindow* overlayWindow = [[RNNOverlayWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  12. [_overlayWindows addObject:overlayWindow];
  13. viewController.view.backgroundColor = [UIColor clearColor];
  14. [overlayWindow setWindowLevel:UIWindowLevelNormal];
  15. [overlayWindow setRootViewController:viewController];
  16. [overlayWindow setHidden:NO];
  17. }
  18. - (void)dismissOverlay:(UIViewController*)viewController {
  19. UIWindow* overlayWindow = [self findWindowByRootViewController:viewController];
  20. [self detachOverlayWindow:overlayWindow];
  21. }
  22. #pragma mark - private
  23. - (void)detachOverlayWindow:(UIWindow *)overlayWindow {
  24. [overlayWindow setHidden:YES];
  25. [overlayWindow setRootViewController:nil];
  26. [_overlayWindows removeObject:overlayWindow];
  27. }
  28. - (UIWindow *)findWindowByRootViewController:(UIViewController *)viewController {
  29. for (UIWindow* window in _overlayWindows) {
  30. if ([window.rootViewController isEqual:viewController]) {
  31. return window;
  32. }
  33. }
  34. return nil;
  35. }
  36. @end