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

思路:自定義View【支付選擇框】,加在 window上,創建一個 蒙版 VIew,加在window 上, 通過 UIVIew 動畫 實現彈出 效果

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 :

// 繳費按鈕點擊

  • (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);
    }
    }];

}

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容