单军华
2018-03-28 f99cf1d5cc50407394501853be06cb39f38a092c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//
//  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()<UIGestureRecognizerDelegate,ASValueTrackingSliderDelegate,ASValueTrackingSliderDataSource>
 
@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