You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
5.7 KiB

//
// CommonPopView.m
// tongxin
//
// Created by ecell on 2023/5/26.
// Copyright © 2023 xTT. All rights reserved.
//
#import "CommonPopView.h"
@interface CommonPopView ()
/// 背景
@property (nonatomic ,weak) UIView *bgView;
@end
@implementation CommonPopView
+ (instancetype)sharedManager{
static dispatch_once_t onceToken;
static CommonPopView *instance;
dispatch_once(&onceToken, ^{
instance = [[CommonPopView alloc] init];
});
return instance;
}
-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.frame = [UIScreen mainScreen].bounds;
self.backgroundColor = RGBA(0, 0, 0, 0.4);
}
return self;
}
- (void)subPopView:(popViewType)type
PopTitle:(NSString *)title
PopText:(NSString *)texts
okTouchBlock:(void (^)(void))okTouchBlock
{
CGSize bgSize;
switch (type) {
case popViewType_dzwl:
bgSize = CGSizeMake(311, 206);
break;
case popViewType_czsb:
bgSize = CGSizeMake(311, 254);
break;
case popViewType_ycgj:
case popViewType_tjlxr:
case popViewType_binding:
bgSize = CGSizeMake(311, 182);
break;
case popViewType_jbsb:
bgSize = CGSizeMake(311, 230);
break;
case popViewType_outLogin:
bgSize = CGSizeMake(311, 146);
break;
case popViewType_zx:
bgSize = CGSizeMake(311, 205);
break;
default:
break;
}
UIView *bgView = [UICommon ui_view:CGRectZero backgroundColor:KKWhiteColorColor cornerRadius:12 borderWidth:0 borderColor:KKWhiteColorColor];
self.bgView = bgView;
[self addSubview:bgView];
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.centerY.equalTo(self);
make.size.mas_equalTo(bgSize);
}];
UILabel *titleLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBold_(18) textColor:KKBlack20 text:title Radius:0];
[bgView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(bgView);
make.top.equalTo(bgView).offset(28);
}];
UILabel *textLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:Font_(16) textColor:KKGrey102 text:@"" Radius:0];
textLabel.attributedText = [self labelFontSize:texts];
[bgView addSubview:textLabel];
[textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.equalTo(bgView).inset(24);
make.top.equalTo(titleLabel.mas_bottom).offset(15);
}];
UIButton *escBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(16) normalColor:KKBlack20 normalText:type == popViewType_tjlxr ? @"容我想想" : @"取消" click:^(id x) {
[self dismiss];
}];
escBtn.layer.borderWidth = 1;
escBtn.layer.borderColor = RGB(240, 239, 237).CGColor;
escBtn.layer.cornerRadius = 24;
//view.layer.masksToBounds = YES;
[bgView addSubview:escBtn];
[escBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.equalTo(bgView.mas_bottom).inset(28);
make.left.equalTo(bgView).offset(24);
make.size.mas_equalTo(CGSizeMake(125, 48));
}];
UIButton *okBtn = [UICommon ui_buttonSimple:CGRectZero font:Font_(16) normalColor:KKWhiteColorColor normalText:type == popViewType_dzwl ? @"去开启" : @"确定" click:^(id x) {
okTouchBlock();
[self dismiss];
}];
okBtn.backgroundColor = mainColor;
okBtn.layer.cornerRadius = 24;
okBtn.layer.masksToBounds = YES;
[bgView addSubview:okBtn];
[okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(escBtn);
make.right.equalTo(bgView.mas_right).inset(24);
make.size.mas_equalTo(CGSizeMake(125, 48));
}];
[self showPopView];
}
- (void)showPopView
{
[self showWithAlert:self.bgView];
[[UIApplication sharedApplication].delegate.window addSubview:self];;
}
/**
添加Alert入场动画
@param alert 添加动画的View
*/
- (void)showWithAlert:(UIView*)alert
{
CAKeyframeAnimation* animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = 0.6;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.1, 1.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
[alert.layer addAnimation:animation forKey:nil];
}
- (void)dismiss
{
[UIView animateWithDuration:0.6f animations:^{
self.backgroundColor = [UIColor clearColor];
self.alpha = 0;
}completion:^(BOOL finished) {
[self removeFromSuperview];
} ];
}
- (NSAttributedString *)labelFontSize:(NSString *)text
{
NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 5;
paragraphStyle.alignment = NSTextAlignmentCenter;
[string addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, string.length)];
return string;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end