從底部彈出【支付選擇框】帶 蒙版

思路:自定義View【支付選擇框】,加在 window上,創(chuàng)建一個(gè) 蒙版 VIew,加在window 上, 通過 UIVIew 動(dòng)畫 實(shí)現(xiàn)彈出 效果

ps: 也可以將蒙版 和 支付框 寫成 懶加載

代碼:

選擇框。h:
typedef void(^dismissViewBlock)();
@property(nonatomic, copy) dismissViewBlock dismissBlock;

選擇框。m: 布局代碼自己布局

  • (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [UIView animateWithDuration:0.5 animations:^{
    self.frame = CGRectMake(0, JKScreenHeight, JKScreenWidth, JKScreenHeight);
    self.dismissBlock();

    }];
    }

控制器。m :

// 繳費(fèi)按鈕點(diǎn)擊

  • (void)payButtonClick:(UIButton *)sender{
    [self.view setUserInteractionEnabled:NO];
    _maskView.frame = CGRectMake(0, 0, JKScreenWidth, JKScreenHeight);
    [UIView animateWithDuration:0.5 animations:^{
    _payView.frame = CGRectMake(0, 0, JKScreenWidth, JKScreenHeight);
    _maskView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];

    }];

}

pragma mark - 支付界面

  • (void)setupPayView{

    RSMeMyNewsRegistrationPayForView * payView = [[RSMeMyNewsRegistrationPayForView alloc] initWithFrame:CGRectMake(0, JKScreenHeight, JKScreenWidth, JKScreenHeight)];

    [[UIApplication sharedApplication].keyWindow addSubview:payView];
    payView.dismissBlock = ^{
    [self dismissMaskView];
    };
    self.payView = payView;
    }

pragma mark - 蒙版

  • (void)setupMaskView{

    UIView * maskView = [[UIView alloc] initWithFrame:CGRectMake(0, JKScreenHeight, JKScreenWidth, JKScreenHeight)];
    [[UIApplication sharedApplication].keyWindow addSubview:maskView];

    /添加手勢事件,移除View/
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissMaskView)];
    [maskView addGestureRecognizer:tapGesture];

    self.maskView = maskView;
    }

//隱藏蒙版

  • (void)dismissMaskView{

    [self.view setUserInteractionEnabled:YES];
    [UIView animateWithDuration:0.5 animations:^{
    _maskView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0];
    } completion:^(BOOL finished) {
    if (finished) {
    _maskView.frame = CGRectMake(0, JKScreenHeight, JKScreenWidth, JKScreenHeight);
    }
    }];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容