Skip to content

Commit

Permalink
* [ios] bug fix picker rescue
Browse files Browse the repository at this point in the history
  • Loading branch information
kfeagle committed Nov 29, 2016
1 parent 2d979a5 commit 27fe3f2
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions ios/sdk/WeexSDK/Sources/Module/WXPickerModule.m
Expand Up @@ -20,7 +20,7 @@ @interface WXPickerModule()

//picker
@property(nonatomic,strong)UIPickerView *picker;
@property(nonatomic,strong)UIView *backgroudView;
@property(nonatomic,strong)UIView *backgroundView;
@property(nonatomic,strong)UIView *pickerView;

//data
Expand Down Expand Up @@ -80,15 +80,15 @@ -(void)show
{
[[[UIApplication sharedApplication] keyWindow] endEditing:YES]; //hide keyboard
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:self.backgroudView];
[window addSubview:self.backgroundView];
if (self.isAnimating) {
return;
}
self.isAnimating = YES;
self.backgroudView.hidden = NO;
self.backgroundView.hidden = NO;
[UIView animateWithDuration:0.35f animations:^{
self.pickerView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - WXPickerHeight, [UIScreen mainScreen].bounds.size.width, WXPickerHeight);
self.backgroudView.alpha = 1;
self.backgroundView.alpha = 1;
} completion:^(BOOL finished) {
self.isAnimating = NO;
}];
Expand All @@ -102,11 +102,11 @@ -(void)hide
self.isAnimating = YES;
[UIView animateWithDuration:0.35f animations:^{
self.pickerView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, WXPickerHeight);
self.backgroudView.alpha = 0;
self.backgroundView.alpha = 0;
} completion:^(BOOL finished) {
self.backgroudView.hidden = YES;
self.backgroundView.hidden = YES;
self.isAnimating = NO;
[self.backgroudView removeFromSuperview];
[self.backgroundView removeFromSuperview];
}];
}

Expand All @@ -129,9 +129,9 @@ -(void)done:(id)sender

-(void)configPickerView
{
self.backgroudView = [self createBackgroudView];
self.backgroundView = [self createbackgroundView];
UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
[self.backgroudView addGestureRecognizer:tapGesture];
[self.backgroundView addGestureRecognizer:tapGesture];
self.pickerView = [self createPickerView];
UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, WXPickerToolBarHeight)];
[toolBar setBackgroundColor:[UIColor whiteColor]];
Expand All @@ -148,7 +148,7 @@ -(void)configPickerView
self.picker.backgroundColor = [UIColor whiteColor];
self.picker.frame = pickerFrame;
[self.pickerView addSubview:self.picker];
[self.backgroudView addSubview:self.pickerView];
[self.backgroundView addSubview:self.pickerView];
}

-(UIView *)createPickerView
Expand All @@ -159,7 +159,7 @@ -(UIView *)createPickerView
return view;
}

-(UIView *)createBackgroudView
-(UIView *)createbackgroundView
{
UIView *view = [UIView new];
view.frame = [UIScreen mainScreen].bounds;
Expand Down Expand Up @@ -216,9 +216,7 @@ -(void)datepick:(NSDictionary *)options callback:(WXModuleCallback)callback
- (void)createDatePicker:(NSDictionary *)options callback:(WXModuleCallback)callback
{
self.callback = callback;
if (!self.datePicker) {
self.datePicker = [[UIDatePicker alloc]init];
}
self.datePicker = [[UIDatePicker alloc]init];
if (UIDatePickerModeDate == self.datePickerMode) {
self.datePicker.datePickerMode = UIDatePickerModeDate;
NSString *value = [WXConvert NSString:options[@"value"]];
Expand Down Expand Up @@ -258,9 +256,9 @@ - (void)createDatePicker:(NSDictionary *)options callback:(WXModuleCallback)call

-(void)configDatePickerView
{
self.backgroudView = [self createBackgroudView];
self.backgroundView = [self createbackgroundView];
UITapGestureRecognizer *tapGesture=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
[self.backgroudView addGestureRecognizer:tapGesture];
[self.backgroundView addGestureRecognizer:tapGesture];
self.pickerView = [self createPickerView];
UIToolbar *toolBar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, WXPickerToolBarHeight)];
[toolBar setBackgroundColor:[UIColor whiteColor]];
Expand All @@ -275,22 +273,22 @@ -(void)configDatePickerView
self.datePicker.frame = pickerFrame;
self.datePicker.backgroundColor = [UIColor whiteColor];
[self.pickerView addSubview:self.datePicker];
[self.backgroudView addSubview:self.pickerView];
[self.backgroundView addSubview:self.pickerView];
}

-(void)showDatePicker
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
[window addSubview:self.backgroudView];
[window addSubview:self.backgroundView];
if (self.isAnimating)
{
return;
}
self.isAnimating = YES;
self.backgroudView.hidden = NO;
self.backgroundView.hidden = NO;
[UIView animateWithDuration:0.35f animations:^{
self.pickerView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - WXPickerHeight, [UIScreen mainScreen].bounds.size.width, WXPickerHeight);
self.backgroudView.alpha = 1;
self.backgroundView.alpha = 1;
} completion:^(BOOL finished) {
self.isAnimating = NO;
}];
Expand All @@ -304,11 +302,11 @@ -(void)hideDatePicker
self.isAnimating = YES;
[UIView animateWithDuration:0.35f animations:^{
self.pickerView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, WXPickerHeight);
self.backgroudView.alpha = 0;
self.backgroundView.alpha = 0;
} completion:^(BOOL finished) {
self.backgroudView.hidden = YES;
self.backgroundView.hidden = YES;
self.isAnimating = NO;
[self.backgroudView removeFromSuperview];
[self.backgroundView removeFromSuperview];
}];
}

Expand Down

0 comments on commit 27fe3f2

Please sign in to comment.