从下往上弹出提醒视图或日期选择视图等等,背景为半透明,弹下去时半透明慢慢消失,最后隐藏
先是背景与日期选择的初始化
-(void)initTimeView{ //时间 背景 提醒视图 //背景透明黑 _blackView = [[UIView alloc]initWithFrame:CGRectMake(0, 60, screen_width, screen_height-60)]; _blackView.backgroundColor = [UIColor clearColor]; UITapGestureRecognizer *touchBlackView = [[UITapGestureRecognizer alloc]init]; [touchBlackView addTarget:self action:@selector(hitRili)]; [_blackView addGestureRecognizer:touchBlackView]; _blackView.hidden = YES; [self.view addSubview:_blackView]; //时间选择 _timeView = [[TimeChooseView alloc]initWithFrame:CGRectMake(0, _blackView.frame.size.height, screen_width, screen_height*6/11)]; _timeView.datepicker.datePickerMode = UIDatePickerModeDate; _timeView.backgroundColor = [UIColor colorWithWhite:0.925 alpha:1.000]; [_timeView.sureBtn addTarget:self action:@selector(HadSelectRiLi) forControlEvents:UIControlEventTouchUpInside]; [_timeView.cancelBtn addTarget:self action:@selector(hitRili) forControlEvents:UIControlEventTouchUpInside]; [_blackView addSubview:_timeView]; }再是定义一个bool类型的show表示是否已经弹出,下面是弹出,弹入的方法 -(void)hitRili{ //日历 if (show == NO) { [UIView animateWithDuration:0.3 animations:^{ _blackView.hidden = NO; _timeView.frame = CGRectMake(0,_blackView.frame.size.height-screen_height*6/11-64, screen_width, screen_height*6/11); _blackView.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.440]; }]; show = YES; }else if (show == YES){ [UIView animateWithDuration:0.3 animations:^{ _timeView.frame = CGRectMake(0, _blackView.frame.size.height, screen_width, screen_height*6/11); _blackView.backgroundColor = [UIColor clearColor]; }completion:^(BOOL finished) { _blackView.hidden = YES; }]; show = NO; } }可以实现渐渐弹出弹入如果一开始存在输入框或者textview 需要用
[self.view endEditing:YES];来提高效果。
