思路:自定義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);
}
}];
}