// // DatePikerView.m // BankQueuingSystem // // Created by 宋伟 on 15/6/10. // Copyright (c) 2015年 com.team.bankQueuing. All rights reserved. // #import "DatePikerView.h" @interface DatePikerView () @property (copy, nonatomic) void(^confirmBlock)(NSDate *date); @property (copy, nonatomic) void(^cancelBlock)(void); @end @implementation DatePikerView static UINib *DatePikerViewNib = nil; + (instancetype)datePikerView{ if (DatePikerViewNib == nil) { DatePikerViewNib = [UINib nibWithNibName:@"DatePikerView" bundle:nil]; } DatePikerView *alert = [[DatePikerViewNib instantiateWithOwner:nil options:nil] lastObject]; return alert; } + (instancetype)initWithDate:(NSDate *)date confirm:(void(^)(NSDate *date))confirmBlock cancle:(void(^)(void))cancleBlock{ DatePikerView *alert = [self datePikerView]; [alert setGesture:YES]; [alert setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 260)]; if (date == nil) { date = [NSDate date]; } [alert.datePickerView setDate:date]; [alert setConfirmBlock:confirmBlock]; [alert setCancelBlock:cancleBlock]; [alert setBackgroundColor:[UIColor whiteColor]]; return alert; } - (CGPoint)centerWithAnimation:(AlertAnimation)animation{ if (animation == kAlertAnimationNone) { CGRect bounds = [UIScreen mainScreen].bounds; CGPoint center = CGPointZero; center.x = bounds.size.width/2; if (IOS7_OR_LATER) { center.y = bounds.size.height - self.bounds.size.height/2; }else{ center.y = bounds.size.height - self.bounds.size.height/2 - 20; } return center; } return [super centerWithAnimation:animation]; } - (IBAction)cancelButtonAction:(id)sender { [self dismissWithAnimation:kAlertAnimationBottom]; if (self.cancelBlock) { self.cancelBlock(); } } - (IBAction)calculateButtonAction:(id)sender { [self dismissWithAnimation:kAlertAnimationBottom]; if (self.confirmBlock) { self.confirmBlock(self.datePickerView.date); } } @end