// // SPSBPickerViewController.m // 我的社保 // // Created by shanp on 2021/5/14. // #import "SPSBPickerViewController.h" #import "SPSBUIGeneralHeader.h" #import "SPSBPickerView.h" @interface SPSBPickerViewController () { UIView *_contentView; SPSBPickerView *_pickerView; } @end @implementation SPSBPickerViewController - (void)viewDidLoad { [super viewDidLoad]; [self setupUI]; } #pragma mark - Action - (void)pickerClickAction:(bool)isConfirm { if (isConfirm && _spsb_finishChose) { @weakify(self) [self closeActionCompletion:^{ @strongify(self) self->_spsb_finishChose(self->_pickerView); }]; return; } [self closeAction]; } - (void)closeAction { [self closeActionCompletion:nil]; } - (void)closeActionCompletion: (void (^_Nullable)(void))completion { [_contentView makeConstraints:^(JXHConstraintMaker *make) { make.top.update(0); }]; [UIView animateWithDuration:0.3 animations:^{ [self.view layoutSubviews]; self.view.backgroundColor = spsb_000000_color(0); } completion:^(BOOL finished) { [self dismissViewControllerAnimated:false completion:completion]; }]; } #pragma mark - Overwrite - (void)showAnimation { [_contentView makeConstraints:^(JXHConstraintMaker *make) { make.top.update(-jxh_viewHeight(self->_contentView)); }]; if (self->_spsb_willDisplay) { self->_spsb_willDisplay(self->_pickerView); } [UIView animateWithDuration:0.3 animations:^{ [self.view layoutSubviews]; self.view.backgroundColor = spsb_000000_color(SPSBPopupViewBackgroundAlpha); }]; } - (void)setupAnimation { self.view.backgroundColor = spsb_000000_color(0.f); } #pragma mark - UI - (void)setupUI { [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeAction)]]; _contentView = UIView.new; _contentView.backgroundColor = spsb_FFFFFF_color(1.f); [self.view addSubview:_contentView]; _pickerView = [[SPSBPickerView alloc] initWithData:_spsb_dataArray]; _pickerView.spsb_pickerViewDelegate = _spsb_pickerDelegate; @weakify(self) _pickerView.spsb_clickButton = ^(bool isConfirm) { @strongify(self) [self pickerClickAction:isConfirm]; }; [_contentView addSubview:_pickerView]; [_pickerView makeConstraints:^(JXHConstraintMaker *make) { make.top.leading.and.trailing.equalTo(0); make.bottom.equalTo(self->_contentView.safebottom); }]; [_contentView makeConstraints:^(JXHConstraintMaker *make) { make.leading.and.trailing.equalTo(0); make.top.equalTo(self.view.bottom); }]; } @end