Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Gdxy committed Apr 15, 2020
1 parent d360ba4 commit 6b8b643
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 18 deletions.
14 changes: 9 additions & 5 deletions TLDatePicker/TLDPPresentationController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIViewControllerContextTransitioning>)transitionContext {
Expand Down
36 changes: 23 additions & 13 deletions TLDatePicker/TLDatePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions TLDatePicker/TLDatePickerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6b8b643

Please sign in to comment.