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