新建一個界面GBDatePickerViewController在裏面初始化相關數據ide
- (void) setupCtrlui
{事件
//背景rem
self.bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];get
self.bgImageView.backgroundColor = [UIColor blackColor];it
self.bgImageView.alpha = 0.5;io
self.bgImageView.userInteractionEnabled = YES;變量
[self.view addSubview:self.bgImageView];date
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideDatePicker:)];file
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;
tapGesture.delegate = self;
[self.bgImageView addGestureRecognizer:tapGesture];
CGFloat height = kSetDateViewHeight;
GBSetDateView *setDateView = [[GBSetDateView alloc] initWithFrame:CGRectMake(0,SCREEN_HEIGHT-kIphone6ScaleH(height), SCREEN_WIDTH,kIphone6ScaleH(height))
calendarType:kProfileInfo.calendarType
selectDate:kProfileInfo.birthday];
setDateView.selectDateDelegate = self.datePickerDelegate;
[self.view addSubview:setDateView];
}
- (void) hideDatePicker:(UITapGestureRecognizer *)sender
{
[self.view removeFromSuperview];
}
在外部調用展現代碼以下:
GBDatePickerViewController *datePickerViewController = [[GBDatePickerViewController alloc] init];
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
[[[UIApplication sharedApplication] keyWindow] addSubview:datePickerViewController.view];
運行界面以下:
點擊黑色的背景,手勢不起做用研究了半天終於找到緣由了
_datePickerViewController = [[GBDatePickerViewController alloc] init];
[[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];
[[[UIApplication sharedApplication] keyWindow] addSubview:_datePickerViewController.view];
把新界面的viewcontroller設成成員變量。該tap就起做用了。手勢事件的響應鏈傳遞。。。。
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。