// // WenDuPickerView.m // GoldRich // // Created by WindShan on 2017/2/16. // Copyright © 2017年 WindShan. All rights reserved. // #import "WenDuPickerView.h" #import "ASValueTrackingSlider.h" typedef void(^doneBlock)(NSString *); @interface WenDuPickerView() @property (nonatomic,strong)doneBlock doneBlock; @property (nonatomic, strong) UIView * buttomView; // 白色背景 @property (nonatomic, strong) ASValueTrackingSlider * trackingSlider; @property (nonatomic, strong) UILabel * tipsLabel; @property (nonatomic, strong) UIButton * doneBtn; @end @implementation WenDuPickerView /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ -(void)setupUI { CGFloat offsetH = SCREEN_HEIGHT/2; _buttomView = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-355)/2, (SCREEN_HEIGHT-300)/2, 355.0, 300.0)]; _buttomView.autoresizesSubviews = YES; _buttomView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; _buttomView.backgroundColor = [UIColor whiteColor]; _buttomView.clearsContextBeforeDrawing = YES; _buttomView.contentMode = UIViewContentModeScaleToFill; _buttomView.multipleTouchEnabled = NO; _buttomView.opaque = YES; _buttomView.userInteractionEnabled = YES; [self addSubview:_buttomView]; self.tipsLabel = [[UILabel alloc] init]; self.tipsLabel.frame = CGRectMake((SCREEN_WIDTH-200)/2, (SCREEN_HEIGHT-300)/2, 200, 60.0); self.tipsLabel.textAlignment = UITextAlignmentCenter; self.tipsLabel.font = [UIFont boldSystemFontOfSize:20]; self.tipsLabel.textColor = RgbColor(84, 76, 155); [self addSubview:self.tipsLabel]; _trackingSlider = [[ASValueTrackingSlider alloc]initWithFrame:CGRectMake(20, (SCREEN_HEIGHT-300)/2 +100, SCREEN_WIDTH-40, 100)]; _trackingSlider.delegate = self; _trackingSlider.dataSource = self; _trackingSlider.popUpViewCornerRadius = 2.0; [_trackingSlider setMaxFractionDigitsDisplayed:0]; _trackingSlider.popUpViewColor = RgbColor(84, 76, 155); _trackingSlider.font = [UIFont fontWithName:@"GillSans-Bold" size:22]; _trackingSlider.textColor = [UIColor whiteColor]; [_trackingSlider showPopUpView]; [self addSubview:_trackingSlider]; _doneBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _doneBtn.frame = CGRectMake(20, (SCREEN_HEIGHT-300)/2+_buttomView.frame.size.height-44-20, SCREEN_WIDTH-40, 44.0); _doneBtn.adjustsImageWhenDisabled = YES; _doneBtn.adjustsImageWhenHighlighted = YES; _doneBtn.alpha = 1.000; _doneBtn.autoresizesSubviews = YES; _doneBtn.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleBottomMargin; _doneBtn.backgroundColor = RgbColor(84, 76, 155); _doneBtn.clearsContextBeforeDrawing = YES; _doneBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; _doneBtn.contentMode = UIViewContentModeScaleToFill; _doneBtn.contentStretch = CGRectFromString(@"{{0, 0}, {1, 1}}"); _doneBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; _doneBtn.enabled = YES; _doneBtn.titleLabel.lineBreakMode = UILineBreakModeMiddleTruncation; _doneBtn.titleLabel.shadowOffset = CGSizeMake(0.0, 0.0); _doneBtn.userInteractionEnabled = YES; [_doneBtn addTarget:self action:@selector(doneAction) forControlEvents:UIControlEventTouchUpInside]; [_doneBtn setTitle:@"确定" forState:UIControlStateNormal]; [self addSubview:_doneBtn]; self.buttomView.layer.masksToBounds = YES; self.buttomView.layer.cornerRadius = 8.0f; self.doneBtn.layer.masksToBounds = YES; self.doneBtn.layer.cornerRadius = 4.0f; //RgbColor(84, 76, 155); self.frame=CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); //点击背景是否影藏 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismiss)]; tap.delegate = self; [self addGestureRecognizer:tap]; //self.bottomConstraint.constant = -self.height; self.backgroundColor = RGBA(0, 0, 0, 0); [self layoutIfNeeded]; [Application.keyWindow bringSubviewToFront:self]; } - (void)doneAction { self.doneBlock(self._wenDuStr); [self dismiss]; } -(instancetype)initWithCompleteBlock:(void(^)(NSString *))completeBlock { self = [super init]; if (self) { [self setupUI]; if (completeBlock) { self.doneBlock = ^(NSString *wenDuStr) { completeBlock(wenDuStr); }; } } return self; } #pragma mark - Action -(void)show { [Application.keyWindow addSubview:self]; _trackingSlider.maximumValue = [_maxValue intValue]; _trackingSlider.minimumValue = [_minValue intValue]; _trackingSlider.formatStr = _fromatStr; [_trackingSlider setValue: [__wenDuStr intValue]]; [self.tipsLabel setText:_titleStr]; [UIView animateWithDuration:.3 animations:^ { //self.bottomConstraint.constant = 10; self.backgroundColor = RGBA(0, 0, 0, 0.3); [self layoutIfNeeded]; }]; } -(void)dismiss { [UIView animateWithDuration:.3 animations:^{ //self.bottomConstraint.constant = -self.height; self.backgroundColor = RGBA(0, 0, 0, 0); [self layoutIfNeeded]; } completion:^(BOOL finished) { [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; [self removeFromSuperview]; }]; } #pragma mark - UIGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if( [touch.view isDescendantOfView:self.buttomView]) { return NO; } return YES; } - (NSString *)slider:(ASValueTrackingSlider *)slider stringForValue:(float)value { NSString * valueStr = [NSString stringWithFormat:@"%d",(int)value]; self._wenDuStr = valueStr; // LOG_INFO(@"当前选择数值:%@℃",self._wenDuStr); return valueStr; } - (void)sliderWillDisplayPopUpView:(ASValueTrackingSlider *)slider{ } - (void)sliderDidHidePopUpView:(ASValueTrackingSlider *)slider{ } @end