SPSBPickerViewController.m 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // SPSBPickerViewController.m
  3. // 我的社保
  4. //
  5. // Created by shanp on 2021/5/14.
  6. //
  7. #import "SPSBPickerViewController.h"
  8. #import "SPSBUIGeneralHeader.h"
  9. #import "SPSBPickerView.h"
  10. @interface SPSBPickerViewController () {
  11. UIView *_contentView;
  12. SPSBPickerView *_pickerView;
  13. }
  14. @end
  15. @implementation SPSBPickerViewController
  16. - (void)viewDidLoad {
  17. [super viewDidLoad];
  18. [self setupUI];
  19. }
  20. #pragma mark - Action
  21. - (void)pickerClickAction:(bool)isConfirm {
  22. if (isConfirm && _spsb_finishChose) {
  23. @weakify(self)
  24. [self closeActionCompletion:^{
  25. @strongify(self)
  26. self->_spsb_finishChose(self->_pickerView);
  27. }];
  28. return;
  29. }
  30. [self closeAction];
  31. }
  32. - (void)closeAction {
  33. [self closeActionCompletion:nil];
  34. }
  35. - (void)closeActionCompletion: (void (^_Nullable)(void))completion {
  36. [_contentView makeConstraints:^(JXHConstraintMaker *make) {
  37. make.top.update(0);
  38. }];
  39. [UIView animateWithDuration:0.3 animations:^{
  40. [self.view layoutSubviews];
  41. self.view.backgroundColor = spsb_000000_color(0);
  42. } completion:^(BOOL finished) {
  43. [self dismissViewControllerAnimated:false completion:completion];
  44. }];
  45. }
  46. #pragma mark - Overwrite
  47. - (void)showAnimation {
  48. [_contentView makeConstraints:^(JXHConstraintMaker *make) {
  49. make.top.update(-jxh_viewHeight(self->_contentView));
  50. }];
  51. if (self->_spsb_willDisplay) {
  52. self->_spsb_willDisplay(self->_pickerView);
  53. }
  54. [UIView animateWithDuration:0.3 animations:^{
  55. [self.view layoutSubviews];
  56. self.view.backgroundColor = spsb_000000_color(SPSBPopupViewBackgroundAlpha);
  57. }];
  58. }
  59. - (void)setupAnimation {
  60. self.view.backgroundColor = spsb_000000_color(0.f);
  61. }
  62. #pragma mark - UI
  63. - (void)setupUI {
  64. [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeAction)]];
  65. _contentView = UIView.new;
  66. _contentView.backgroundColor = spsb_FFFFFF_color(1.f);
  67. [self.view addSubview:_contentView];
  68. _pickerView = [[SPSBPickerView alloc] initWithData:_spsb_dataArray];
  69. _pickerView.spsb_pickerViewDelegate = _spsb_pickerDelegate;
  70. @weakify(self)
  71. _pickerView.spsb_clickButton = ^(bool isConfirm) {
  72. @strongify(self)
  73. [self pickerClickAction:isConfirm];
  74. };
  75. [_contentView addSubview:_pickerView];
  76. [_pickerView makeConstraints:^(JXHConstraintMaker *make) {
  77. make.top.leading.and.trailing.equalTo(0);
  78. make.bottom.equalTo(self->_contentView.safebottom);
  79. }];
  80. [_contentView makeConstraints:^(JXHConstraintMaker *make) {
  81. make.leading.and.trailing.equalTo(0);
  82. make.top.equalTo(self.view.bottom);
  83. }];
  84. }
  85. @end