From 6b8b643b2d4974d0037c535027fec73f2ba4d2db Mon Sep 17 00:00:00 2001 From: Gdxy Date: Wed, 15 Apr 2020 15:06:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TLDatePicker/TLDPPresentationController.m | 14 +++++---- TLDatePicker/TLDatePicker.m | 36 +++++++++++++++-------- TLDatePicker/TLDatePickerView.m | 11 +++++++ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/TLDatePicker/TLDPPresentationController.m b/TLDatePicker/TLDPPresentationController.m index c66c10d..fc5b6d9 100644 --- a/TLDatePicker/TLDPPresentationController.m +++ b/TLDatePicker/TLDPPresentationController.m @@ -152,15 +152,19 @@ - (void)containerViewWillLayoutSubviews { // MARK: - Tap Gesture Recognizer - (void)dimmingViewTapped:(UITapGestureRecognizer *)sender { - if (self.didTapMaskView) { - self.didTapMaskView(); - } if (!self.disableTapMaskToDismiss) { - [self.presentingViewController dismissViewControllerAnimated:YES completion:NULL]; + [self.presentingViewController dismissViewControllerAnimated:YES completion:^{ + if (self.didTapMaskView) { + self.didTapMaskView(); + } + }]; + }else { + if (self.didTapMaskView) { + self.didTapMaskView(); + } } } - // MARK: - UIViewControllerAnimatedTransitioning - (NSTimeInterval)transitionDuration:(id)transitionContext { diff --git a/TLDatePicker/TLDatePicker.m b/TLDatePicker/TLDatePicker.m index b21264e..fb40223 100644 --- a/TLDatePicker/TLDatePicker.m +++ b/TLDatePicker/TLDatePicker.m @@ -148,24 +148,34 @@ - (void)layoutTopBarSubviews { // MARK: - Actions - (void)cancel:(UIButton *)btn { - - if (self.picekerEvent) { - self.picekerEvent(self.selectedDate, TLDatePickerEventTypeCancelButtonDidClicked); + + if(self.disableDismissByCancelButton) { + if (self.picekerEvent) { + self.picekerEvent(self.selectedDate, TLDatePickerEventTypeCancelButtonDidClicked); + } + return; + }else { + [self dismissAnimated:YES completion:^{ + if (self.picekerEvent) { + self.picekerEvent(self.selectedDate, TLDatePickerEventTypeCancelButtonDidClicked); + } + }]; } - - if(self.disableDismissByCancelButton) return; - - [self dismissAnimated:YES completion:nil]; } - (void)commit:(UIButton *)btn { - if (self.picekerEvent) { - self.picekerEvent(self.selectedDate, TLDatePickerEventTypeDoneButtonDidClicked); + if(self.disableDismissByDoneButton) { + if (self.picekerEvent) { + self.picekerEvent(self.selectedDate, TLDatePickerEventTypeDoneButtonDidClicked); + } + return; + }else { + [self dismissAnimated:YES completion:^{ + if (self.picekerEvent) { + self.picekerEvent(self.selectedDate, TLDatePickerEventTypeDoneButtonDidClicked); + } + }]; } - - if(self.disableDismissByDoneButton) return; - - [self dismissAnimated:YES completion:nil]; } // MARK: - API diff --git a/TLDatePicker/TLDatePickerView.m b/TLDatePicker/TLDatePickerView.m index 0b554db..217177a 100644 --- a/TLDatePicker/TLDatePickerView.m +++ b/TLDatePicker/TLDatePickerView.m @@ -96,6 +96,17 @@ - (void)setMode:(TLDatePickerMode)mode - (void)resetParams { + if (self.mode < TLDatePickerModeTime) { + if (self.maxDate) { + NSString *date = [NSString stringWithFormat:@"%zi-%zi-%zi 23:59:59", self.maxDate.year, self.maxDate.month, self.maxDate.day]; + self.maxDate = [NSDate dateWithFormatString:date]; + } + if (self.minDate) { + NSString *date = [NSString stringWithFormat:@"%zi-%zi-%zi 00:00:00", self.minDate.year, self.minDate.month, self.minDate.day]; + self.minDate = [NSDate dateWithFormatString:date]; + } + } + if (!self.date) { self.date = [NSDate date]; if (self.maxDate && [self.maxDate compareFrom:self.date] < 0) {