提交
This commit is contained in:
152
QXLive/Base/QXAlertViewController.m
Normal file
152
QXLive/Base/QXAlertViewController.m
Normal file
@@ -0,0 +1,152 @@
|
||||
//
|
||||
// QXAlertViewController.m
|
||||
// QXLive
|
||||
//
|
||||
// Created by 启星 on 2025/4/27.
|
||||
//
|
||||
|
||||
#import "QXAlertViewController.h"
|
||||
|
||||
@interface QXAlertViewController ()<UIGestureRecognizerDelegate>
|
||||
|
||||
@property(nonatomic,copy)void (^closeBlock)(void);
|
||||
@end
|
||||
|
||||
@implementation QXAlertViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
self.view.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.3];
|
||||
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
|
||||
tap.delegate = self;
|
||||
[self.view addGestureRecognizer:tap];
|
||||
|
||||
}
|
||||
-(void)viewDidAppear:(BOOL)animated{
|
||||
[super viewDidAppear:animated];
|
||||
[self beginShow];
|
||||
}
|
||||
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
||||
[self.view endEditing:YES];
|
||||
}
|
||||
-(void)beginShow{
|
||||
_alertView.centerX = self.view.centerX;
|
||||
switch (_popType) {
|
||||
case PopViewTypeBottomToUpActionSheet:{
|
||||
_alertView.y = SCREEN_HEIGHT;
|
||||
[self.view addSubview:_alertView];
|
||||
[UIView animateWithDuration:0.3 animations:^{
|
||||
self->_alertView.y = (SCREEN_HEIGHT-self->_alertView.height);
|
||||
} completion:^(BOOL finished) {
|
||||
|
||||
}];
|
||||
}
|
||||
break;
|
||||
case PopViewTypePopFromCenter:{
|
||||
_alertView.centerX = self.view.centerX;
|
||||
_alertView.centerY = self.view.centerY;
|
||||
[self.view addSubview:_alertView];
|
||||
_alertView.transform = CGAffineTransformMakeScale(0.1, 0.1);
|
||||
// 弹性动画
|
||||
[UIView animateWithDuration:0.3
|
||||
delay:0
|
||||
usingSpringWithDamping:0.9
|
||||
initialSpringVelocity:0.1
|
||||
options:UIViewAnimationOptionCurveEaseInOut
|
||||
animations:^{
|
||||
self->_alertView.transform = CGAffineTransformIdentity;
|
||||
} completion:nil];
|
||||
}
|
||||
|
||||
break;
|
||||
case PopViewTypeTopToCenter:{
|
||||
_alertView.y = -SCREEN_HEIGHT;
|
||||
[self.view addSubview:_alertView];
|
||||
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
||||
self->_alertView.y = (SCREEN_HEIGHT-self->_alertView.height)/2.0;
|
||||
} completion:^(BOOL finished) {
|
||||
|
||||
}];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
-(void)tapAction{
|
||||
if (!self.tapDismiss) {
|
||||
return;
|
||||
}
|
||||
[self hideViewFinishBlock:self.closeBlock];
|
||||
}
|
||||
|
||||
-(void)hideViewFinishBlock:(void (^)(void))closeBlock{
|
||||
MJWeakSelf
|
||||
switch (_popType) {
|
||||
case PopViewTypeBottomToUpActionSheet:{
|
||||
[UIView animateWithDuration:0.3 animations:^{
|
||||
self->_alertView.y = SCREEN_HEIGHT;
|
||||
} completion:^(BOOL finished) {
|
||||
[self->_alertView removeFromSuperview];
|
||||
[self dismissViewControllerAnimated:NO completion:^{
|
||||
if (closeBlock) {
|
||||
closeBlock();
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}
|
||||
break;
|
||||
case PopViewTypePopFromCenter:{
|
||||
[UIView animateWithDuration:0.3
|
||||
delay:0
|
||||
usingSpringWithDamping:0.9
|
||||
initialSpringVelocity:1
|
||||
options:UIViewAnimationOptionCurveEaseInOut
|
||||
animations:^{
|
||||
self->_alertView.transform = CGAffineTransformMakeScale(0.001, 0.001);
|
||||
} completion:^(BOOL finished) {
|
||||
[self->_alertView removeFromSuperview];
|
||||
[self dismissViewControllerAnimated:NO completion:^{
|
||||
if (closeBlock) {
|
||||
closeBlock();
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}
|
||||
break;
|
||||
case PopViewTypeTopToCenter:{
|
||||
[UIView animateWithDuration:0.3 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:1 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
||||
self->_alertView.y = SCREEN_HEIGHT;
|
||||
} completion:^(BOOL finished) {
|
||||
[self->_alertView removeFromSuperview];
|
||||
[self dismissViewControllerAnimated:NO completion:^{
|
||||
if (closeBlock) {
|
||||
closeBlock();
|
||||
}
|
||||
}];
|
||||
}];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
-(void)setPopType:(PopViewType)popType{
|
||||
_popType = popType;
|
||||
}
|
||||
|
||||
-(void)setAlertView:(UIView *)alertView{
|
||||
if (_alertView) {
|
||||
[_alertView removeFromSuperview];
|
||||
_alertView = nil;
|
||||
}
|
||||
_alertView = alertView;
|
||||
}
|
||||
|
||||
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
|
||||
return touch.view == self.view;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user