iOS开发 从下往上弹出提醒视图或日期选择视图等等背景为半透明

从下往上弹出提醒视图或日期选择视图等等,背景为半透明,弹下去时半透明慢慢消失,最后隐藏

先是背景与日期选择的初始化

-(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];
来提高效果。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值