SPSBPopupViewController.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // SPSBPopupViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/4/26.
  6. //
  7. #import "SPSBPopupViewController.h"
  8. @interface SPSBPopupViewController ()
  9. @end
  10. @implementation SPSBPopupViewController
  11. - (instancetype)init {
  12. self = [super init];
  13. if (!self) return nil;
  14. self.modalPresentationStyle = UIModalPresentationCustom;
  15. return self;
  16. }
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self setupAnimation];
  20. }
  21. - (void)viewWillAppear:(BOOL)animated {
  22. [super viewWillAppear:animated];
  23. if (!self.isBeingPresented) {
  24. [self.presentingViewController viewWillAppear:animated];
  25. }
  26. }
  27. - (void)viewDidAppear:(BOOL)animated {
  28. [super viewDidAppear:animated];
  29. if (!self.isBeingPresented) {
  30. [self.presentingViewController viewDidAppear:animated];
  31. } else {
  32. [self.view setNeedsLayout];
  33. [self.view layoutIfNeeded];
  34. [self showAnimation];
  35. }
  36. }
  37. - (void)viewWillDisappear:(BOOL)animated {
  38. [super viewWillDisappear:animated];
  39. if (!self.isBeingDismissed) {
  40. [self.presentingViewController viewWillDisappear:animated];
  41. }
  42. }
  43. - (void)viewDidDisappear:(BOOL)animated {
  44. [super viewDidDisappear:animated];
  45. if (!self.isBeingDismissed) {
  46. [self.presentingViewController viewDidDisappear:animated];
  47. }
  48. }
  49. - (UIStatusBarStyle)preferredStatusBarStyle {
  50. UIViewController *vc = self.presentingViewController;
  51. if ([vc isKindOfClass:[UINavigationController class]]) {
  52. return ((UIViewController *)((UINavigationController *)self.presentingViewController).viewControllers.lastObject).preferredStatusBarStyle;
  53. } else {
  54. return vc.preferredStatusBarStyle;
  55. }
  56. return self.presentingViewController.preferredStatusBarStyle;
  57. }
  58. - (void)setupAnimation {
  59. self.view.alpha = 0;
  60. }
  61. - (void)hideAnimation:(void(^_Nullable)(BOOL))completion {
  62. [UIView animateWithDuration:0.3 animations:^{
  63. self.view.alpha = 0;
  64. } completion:completion];
  65. }
  66. - (void)showAnimation {
  67. [UIView animateWithDuration:0.3 animations:^{
  68. self.view.alpha = 1;
  69. }];
  70. }
  71. @end