.h文件
#import
typedef void(^commitBlock)(NSString * code);
@interface ENAlertView : UIView
- (id)initWithTitle:(NSString *)title
contentText:(NSString *)content
textAlignment:(NSTextAlignment)textAlignment
leftButtonTitle:(NSString *)leftTitle
rightButtonTitle:(NSString *)rigthTitle
isDynamic:(BOOL)isDynamic;
- (id)initWithAlertViewTitle:(NSString *)title
contentText:(NSString *)content
textAlignment:(NSTextAlignment)textAlignment
leftButtonTitle:(NSString *)leftTitle
rightButtonTitle:(NSString *)rigthTitle
showClose:(BOOL)isShow;
- (id)initWithTitle:(NSString *)title
textViewBlock:(commitBlock)commitBlock
contentText:(NSString *)content
leftButtonTitle:(NSString *)leftTitle
rightButtonTitle:(NSString *)rightTitle;
- (void)show;
@property (nonatomic, copy) void (^leftBlock)(void);
@property (nonatomic, copy) void (^rightBlock)(void);
@property (nonatomic, copy) void (^dismissBlock)(void);
@property (copy, nonatomic) void (^commitBlock)(NSString *code);
@end
.m文件
#import
//#import "UIImage+Additions.h"
#import "UIImage+UIColor.h"
#import "ENAlertView.h"
#import "NSString+Frame.h"
#define kAlertWidth WIDTHRADIUS*280.f
#define kAlertHeight WIDTHRADIUS*196.f
#define kAlertHeightTime SCREEN_WIDTH/320*200.0f
#define kAlertCodeHeight 210.0f
#define kTitleYOffset WIDTHRADIUS*45.0f
#define kTitleHeight WIDTHRADIUS*50.0f
#define contentLabelHeight WIDTHRADIUS*52.0f
#define kButtonHeight WIDTHRADIUS*50 //32.0/320*SCREEN_WIDTH
#define kButtonWidth WIDTHRADIUS*230.5/320*SCREEN_WIDTH
#define kSingleButtonWidth WIDTHRADIUS*461.0/2*SCREEN_WIDTH/320
#define kCoupleButtonWidth WIDTHRADIUS*112.25*SCREEN_WIDTH/320
#define kCoupleButtonOffset WIDTHRADIUS*10
#define kButtonBottomOffset WIDTHRADIUS*5.0f
@interface ENAlertView ()
{
BOOL _leftLeave;
BOOL timeShow;
BOOL codeShow;
dispatch_source_t _timer;
}
@property (nonatomic, strong) UIView *backImageView;
@property (nonatomic, strong) UILabel *alertTitleLabel;
@property (nonatomic, strong) UILabel *alertContentLabel;
@property (nonatomic, strong) UIButton *leftBtn;
@property (nonatomic, strong) UIButton *rightBtn;
@property (nonatomic, strong) UIView *headerView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *timeShowLabel;
@property (nonatomic,strong) UIView *timeView;
@property (nonatomic,strong) UIView *lineView;
@property (nonatomic, copy) NSString *code;
@property (nonatomic,strong) UIButton *commit;
@property (nonatomic,strong) UIButton *close;
@property (nonatomic,strong) UITapGestureRecognizer *tap;
@property (nonatomic,assign) CGFloat contentHeight;
@property (nonatomic,assign) CGFloat titleHeight;
@property (nonatomic,assign) BOOL isShow;
@property (nonatomic,assign) BOOL isDynamic;
@property (nonatomic,assign) BOOL isAdd;
@property (nonatomic,strong) UITextView *tvText;
@end
@implementation ENAlertView
#pragma mark - Life Cycle
- (id)initWithTitle:(NSString *)title
contentText:(NSString *)content
textAlignment:(NSTextAlignment)textAlignment
leftButtonTitle:(NSString *)leftTitle
rightButtonTitle:(NSString *)rigthTitle
isDynamic:(BOOL)isDynamic{
self = [super init];
if (self) {
self.isDynamic = isDynamic;
self.layer.cornerRadius = 10.0;
self.backgroundColor = [UIColor whiteColor];
self.layer.masksToBounds = YES;
CGFloat titleHeight = [title heightWithSystemFont:REGULAR_FONT(25) maxWidth:kAlertWidth]+10*WIDTHRADIUS;//10*WIDTHRADIUS 高度增加 文字到上下距离
_titleHeight = titleHeight;
self.alertTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, -1, kAlertWidth, _titleHeight)];//kTitleHeight
self.alertTitleLabel.font = MEDIUM_FONT(17);
self.alertTitleLabel.textColor = Color_White;
self.alertTitleLabel.backgroundColor = Color_Theme;
self.alertTitleLabel.textAlignment = NSTextAlignmentCenter;
self.alertTitleLabel.numberOfLines = 0;
[self addSubview:self.alertTitleLabel];
CGFloat contentLabelWidth = kAlertWidth - 62*WIDTHRADIUS;
CGFloat contentHeight = [content heightWithSystemFont:REGULAR_FONT(15) maxWidth:contentLabelWidth]+10*WIDTHRADIUS;//10*WIDTHRADIUS 高度增加 文字到上下距离
_contentHeight = contentHeight;//赋值
self.alertContentLabel = [[UILabel alloc] initWithFrame:CGRectMake((kAlertWidth - contentLabelWidth) * 0.5, CGRectGetMaxY(self.alertTitleLabel.frame)+1, contentLabelWidth,_contentHeight)];//contentLabelHeight
self.alertContentLabel.textAlignment = textAlignment;
self.alertContentLabel.numberOfLines = 0;
self.alertContentLabel.textColor =Color_Title;
self.alertContentLabel.font = REGULAR_FONT(15);
[self addSubview:self.alertContentLabel];
//不显示标题 直接显示内容 居中
if (! (content && ![content isEqualToString:@""])) {
[self.alertContentLabel removeFromSuperview];
_contentHeight = 0;
// self.alertContentLabel.frame = CGRectMake((kAlertWidth - contentLabelWidth) * 0.5, 25*WIDTHRADIUS, contentLabelWidth, kTitleHeight + contentLabelHeight);
}else{
// UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, _titleHeight, SCREEN_WIDTH, 1)];
// line.backgroundColor = Color_LineColor;
// [self addSubview:line];
}
UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(0,_titleHeight +_contentHeight, SCREEN_WIDTH, 1)];
line1.backgroundColor = Color_LineColor;
[self addSubview:line1];
CGRect leftBtnFrame;
CGRect rightBtnFrame;
if (!leftTitle) {
rightBtnFrame = CGRectMake(0, _titleHeight+_contentHeight, kAlertWidth, kButtonHeight);
self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.rightBtn.frame = rightBtnFrame;
}else {
leftBtnFrame = CGRectMake(0, _titleHeight+_contentHeight, kAlertWidth/2-1, kButtonHeight);
rightBtnFrame = CGRectMake(CGRectGetMaxX(leftBtnFrame), _titleHeight+_contentHeight, kAlertWidth/2-1, kButtonHeight);
self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.leftBtn.frame = leftBtnFrame;
self.rightBtn.frame = rightBtnFrame;
self.lineView = [[UIView alloc]initWithFrame:CGRectMake(kAlertWidth/2, CGRectGetMaxY(rightBtnFrame)-36*WIDTHRADIUS,1,22*WIDTHRADIUS)];
self.lineView.backgroundColor = Color_LineColor;
}
// [self.rightBtn setBackgroundImage: ImageNamed(@"button_theme_background")/*[UIImage imageWithColor:UIColorFromRGB(rightColorHex)]*/ forState:UIControlStateNormal];
[self.rightBtn setBackgroundColor:[UIColor clearColor]];
[self.leftBtn setBackgroundColor:[UIColor clearColor]];
[self.rightBtn setTitle:rigthTitle forState:UIControlStateNormal];
[self.leftBtn setTitle:leftTitle forState:UIControlStateNormal];
self.leftBtn.titleLabel.font = self.rightBtn.titleLabel.font = MEDIUM_FONT(17);
[self.leftBtn setTitleColor:Color_Content forState:UIControlStateNormal];
[self.rightBtn setTitleColor:Color_Theme forState:UIControlStateNormal];
[self.leftBtn addTarget:self action:@selector(leftBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.rightBtn addTarget:self action:@selector(rightBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
// self.leftBtn.layer.masksToBounds = self.rightBtn.layer.masksToBounds = YES;
// self.leftBtn.layer.cornerRadius = self.rightBtn.layer.cornerRadius = 3.0;
[self addSubview:self.leftBtn];
[self addSubview:self.rightBtn];
[self addSubview:self.lineView];
self.alertTitleLabel.text = title;
//设置内容行间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineSpacing = 0;
paragraphStyle.alignment = textAlignment;
NSDictionary *attributes = @{ NSParagraphStyleAttributeName:paragraphStyle};
self.alertContentLabel.attributedText = [[NSAttributedString alloc]initWithString:DSStringValue(content) attributes:attributes];
self.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
}
return self;
}
//新的提示d窗样式
- (id)initWithAlertViewTitle:(NSString *)title
contentText:(NSString *)content
textAlignment:(NSTextAlignment)textAlignment
leftButtonTitle:(NSString *)leftTitle
rightButtonTitle:(NSString *)rigthTitle
showClose:(BOOL)isShow{
self = [super init];
if (self) {
// self.isShow = isShow;
self.isShow = NO;
self.layer.cornerRadius = 10.0;
self.backgroundColor = [UIColor whiteColor];
self.layer.masksToBounds = YES;
CGFloat contentLabelWidth = kAlertWidth - 62*WIDTHRADIUS;
CGFloat titleHeight = ceilf([title heightWithSystemFont:REGULAR_FONT(17) maxWidth:contentLabelWidth]);//10*WIDTHRADIUS 高度增加 文字到上下距离
self.alertTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,10, kAlertWidth+2, titleHeight)];//15*WIDTHRADIUS
self.alertTitleLabel.font = MEDIUM_FONT(17);
self.alertTitleLabel.textColor = Color_Title;
self.alertTitleLabel.backgroundColor = Color_White;
self.alertTitleLabel.textAlignment = NSTextAlignmentCenter;
[self addSubview:self.alertTitleLabel];
CGFloat contentHeight = ceilf([content getSpaceLabelHeightwithFont:REGULAR_FONT(13) withWidth:contentLabelWidth lineSpacing:5]) ;//10*WIDTHRADIUS 高度增加 文字到上下距离
// CGFloat contentHeight = ceilf([content heightWithSystemFont:REGULAR_FONT(13) maxWidth:contentLabelWidth]+5*WIDTHRADIUS) ;//10*WIDTHRADIUS 高度增加 文字到上下距离
self.alertContentLabel = [[UILabel alloc] initWithFrame:CGRectMake((kAlertWidth - contentLabelWidth) * 0.5, CGRectGetMaxY(self.alertTitleLabel.frame), contentLabelWidth, contentHeight)];
self.alertContentLabel.textAlignment = textAlignment;
self.alertContentLabel.numberOfLines = 0;
self.alertContentLabel.textColor =Color_Title;
self.alertContentLabel.font = REGULAR_FONT(13);
[self addSubview:self.alertContentLabel];
//不显示标题 直接显示内容 居中
if (! (title && ![title isEqualToString:@""])) {
[self.alertTitleLabel removeFromSuperview];
self.alertContentLabel.frame = CGRectMake((kAlertWidth - contentLabelWidth) * 0.5, 15*WIDTHRADIUS, contentLabelWidth, titleHeight +contentHeight);
}else{
// UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 50*WIDTHRADIUS, SCREEN_WIDTH, 1)];
// line.backgroundColor = Color_LineColor;
// [self addSubview:line];
}
UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.alertContentLabel.frame)+15*WIDTHRADIUS, SCREEN_WIDTH, 1)];
line1.backgroundColor = Color_LineColor;
[self addSubview:line1];
CGRect leftBtnFrame;
CGRect rightBtnFrame;
if (!leftTitle) {
rightBtnFrame = CGRectMake(0,CGRectGetMaxY(line1.frame), kAlertWidth, kButtonHeight);
self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.rightBtn.frame = rightBtnFrame;
}else {
leftBtnFrame = CGRectMake(0, CGRectGetMaxY(line1.frame), kAlertWidth/2-1, kButtonHeight);
rightBtnFrame = CGRectMake(CGRectGetMaxX(leftBtnFrame), CGRectGetMaxY(line1.frame), kAlertWidth/2-1, kButtonHeight);
self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
self.leftBtn.frame = leftBtnFrame;
self.rightBtn.frame = rightBtnFrame;
self.lineView = [[UIView alloc]initWithFrame:CGRectMake(kAlertWidth/2, CGRectGetMaxY(line1.frame),1,kButtonHeight)];
self.lineView.backgroundColor = Color_LineColor;
}
// [self.rightBtn setBackgroundImage: ImageNamed(@"button_theme_background")/*[UIImage imageWithColor:UIColorFromRGB(rightColorHex)]*/ forState:UIControlStateNormal];
[self.rightBtn setBackgroundColor:[UIColor clearColor]];
[self.leftBtn setBackgroundColor:[UIColor clearColor]];
[self.rightBtn setTitle:rigthTitle forState:UIControlStateNormal];
[self.leftBtn setTitle:leftTitle forState:UIControlStateNormal];
self.leftBtn.titleLabel.font = self.rightBtn.titleLabel.font = MEDIUM_FONT(16);
[self.leftBtn setTitleColor:Color_Content forState:UIControlStateNormal];
[self.rightBtn setTitleColor:Color_Theme forState:UIControlStateNormal];
[self.leftBtn addTarget:self action:@selector(leftBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.rightBtn addTarget:self action:@selector(rightBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
// self.leftBtn.layer.masksToBounds = self.rightBtn.layer.masksToBounds = YES;
// self.leftBtn.layer.cornerRadius = self.rightBtn.layer.cornerRadius = 3.0;
[self addSubview:self.leftBtn];
[self addSubview:self.rightBtn];
[self addSubview:self.lineView];
_close = [[UIButton alloc] init];
_close.hidden = isShow == false;
[_close setImage:ImageNamed(@"announcement_close") forState:UIControlStateNormal];
[_close addTarget:self action:@selector(clickClose) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_close];
[self.close mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.mas_top);
make.right.equalTo(self.mas_right);
make.size.mas_equalTo(CGSizeMake(45, 45));
}];
self.alertTitleLabel.text = title;
//设置内容行间距
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineSpacing = 5;
paragraphStyle.alignment = textAlignment;
NSDictionary *attributes = @{ NSParagraphStyleAttributeName:paragraphStyle};
self.alertContentLabel.attributedText = [[NSAttributedString alloc]initWithString:DSStringValue(content) attributes:attributes];
self.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
_contentHeight = CGRectGetMaxY(self.alertContentLabel.frame)+15*WIDTHRADIUS+1 + kButtonHeight;
}
return self;
}
- (id)initWithTitle:(NSString *)title
textViewBlock:(commitBlock)commitBlock
contentText:(NSString *)content
leftButtonTitle:(NSString *)leftTitle
rightButtonTitle:(NSString *)rightTitle{
self = [super init];
if (self) {
codeShow = YES;
self.frame =CGRectMake(33, 170, SCREEN_WIDTH - 66, kAlertCodeHeight);
self.backgroundColor = Color_White;
self.layer.cornerRadius = 10;
self.layer.masksToBounds = YES;
UILabel *titleLab = [[UILabel alloc ]init];
titleLab.textColor = Color_White;
titleLab.text= title;
titleLab.numberOfLines = 2;
titleLab.font = FontSystem(15*WIDTHRADIUS);
titleLab.textAlignment = NSTextAlignmentCenter;
titleLab.backgroundColor = Color_Theme;
[self addSubview:titleLab];
_tvText = [[UITextView alloc]init];
_tvText.backgroundColor = [UIColor colorWithHex:0xf9f9f9];
_tvText.delegate = self;
_tvText.tag = 4;
_tvText.layer.borderWidth = 0.5;
_tvText.layer.borderColor = Color_LineColor.CGColor;
_tvText.layer.cornerRadius = 5;
_tvText.textColor = Color_Title;
[_tvText setAutocapitalizationType:UITextAutocapitalizationTypeNone];
[self addSubview:_tvText];
self.commitBlock = commitBlock;
UIView *line = [[UIView alloc] init];
line.backgroundColor = Color_LineColor;
[self addSubview:line];
UIButton *cancle = [[UIButton alloc] init];
[cancle setTitle:leftTitle forState:UIControlStateNormal];
cancle.titleLabel.font = FontSystem(18*WIDTHRADIUS);
[cancle setTitleColor:Color_Content forState:UIControlStateNormal];
[cancle addTarget:self action:@selector(cancle) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:cancle];
UIView *line1 = [[UIView alloc] init];
line1.backgroundColor = Color_LineColor;
[self addSubview:line1];
_commit = [[UIButton alloc] init];
[_commit setTitle:rightTitle forState:UIControlStateNormal];
_commit.titleLabel.font = FontSystem(18*WIDTHRADIUS);
[_commit setTitleColor:Color_Theme forState:UIControlStateNormal];
[_commit addTarget:self action:@selector(commitOpinion) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_commit];
[titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.right.equalTo(self);
make.height.mas_equalTo(50*WIDTHRADIUS);
}];
[_tvText mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(titleLab.mas_bottom).offset(20);
make.left.equalTo(self.mas_left).offset(20);
make.right.equalTo(self.mas_right).offset(-20);
make.height.mas_equalTo(70 *WIDTHRADIUS);
}];
[line mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.tvText.mas_bottom).offset(10);
make.left.right.equalTo(self);
make.height.equalTo(@1);
}];
[line1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(line.mas_bottom);
make.centerX.equalTo(self.mas_centerX);
make.width.equalTo(@(0.5));
make.bottom.equalTo(self.mas_bottom);
}];
[cancle mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(line.mas_bottom);
make.left.equalTo(self.mas_left);
make.right.equalTo(line1.mas_left);
make.bottom.equalTo(self.mas_bottom);
}];
[self.commit mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(line.mas_bottom);
make.left.equalTo(line1.mas_right);
make.right.equalTo(self.mas_right);
make.bottom.equalTo(self.mas_bottom);
}];
_contentHeight = kAlertHeight;
self.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
}
return self;
}
- (void)show {
[[UIApplication sharedApplication].keyWindow endEditing:YES];
UIViewController *topVC = [self appRootViewController];
if (_isDynamic) {//[_rightBtn.titleLabel.text isEqualToString:@"更新"]
self.frame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, - (50*WIDTHRADIUS+_contentHeight+_titleHeight) - 30, kAlertWidth, _contentHeight+50*WIDTHRADIUS+_titleHeight);
}else{
// self.frame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, - kAlertHeight - 30, kAlertWidth, kAlertHeight);
//新的frame
self.frame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, - _contentHeight, kAlertWidth, _contentHeight);
}
if (timeShow) {
self.frame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, - kAlertHeightTime - 30, kAlertWidth, kAlertHeightTime);
}
if (codeShow) {
self.frame = CGRectMake(33, 150, SCREEN_WIDTH - 66, kAlertCodeHeight);
}
if (self.isAdd) {
self.frame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, - _contentHeight, kAlertWidth, _contentHeight);
}
[self exChangeOut:self dur:0.4f];
[[UIApplication sharedApplication].keyWindow addSubview:self];
}
- (void)hide:(UIButton *)sender {
[self removeFromSuperviews];
if (self.dismissBlock) {
self.dismissBlock();
}
}
-(void)closeTapping{
[self removeFromSuperviews];
if (self.dismissBlock) {
self.dismissBlock();
}
}
//完全自适应alertView
- (void)leftBtnClicked:(id)sender
{
_leftLeave = YES;
[self hide:nil];
if (self.leftBlock) {
self.leftBlock();
}
}
- (void)rightBtnClicked:(id)sender {
if (_leftBtn.titleLabel.text.length != 0 || ![_rightBtn.titleLabel.text isEqualToString:@"更新"]) {
_leftLeave = NO;
[self hide:nil];
}
if (self.rightBlock) {
self.rightBlock();
}
}
- (UIViewController *)appRootViewController {
UIViewController *appRootVC = [UIApplication sharedApplication].keyWindow.rootViewController;
UIViewController *topVC = appRootVC;
while (topVC.presentedViewController) {
topVC = topVC.presentedViewController;
}
return topVC;
}
- (void)removeFromSuperviews {
[self.backImageView removeFromSuperview];
self.backImageView = nil;
UIViewController *topVC = [self appRootViewController];
CGRect afterFrame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, CGRectGetHeight(topVC.view.bounds), kAlertWidth, kAlertHeight);
if (_isDynamic) {//[_rightBtn.titleLabel.text isEqualToString:@"更新"]
afterFrame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, CGRectGetHeight(topVC.view.bounds), kAlertWidth, _contentHeight+50*WIDTHRADIUS+_titleHeight);
}
[UIView animateWithDuration:0 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
self.frame = afterFrame;
if (_leftLeave) {
self.transform = CGAffineTransformMakeRotation(-M_1_PI / 1.5);
}else {
self.transform = CGAffineTransformMakeRotation(M_1_PI / 1.5);
}
} completion:^(BOOL finished) {
//注释原因:DXAlertViewd框切后台会在这crash
[self removeFromSuperview];
}];
}
- (void)willMoveToSuperview:(UIView *)newSuperview {
if (newSuperview == nil) {
return;
}
UIViewController *topVC = [self appRootViewController];
if (!self.backImageView) {
self.backImageView = [[UIView alloc] initWithFrame:topVC.view.bounds];
self.backImageView.backgroundColor = [UIColor blackColor];
self.backImageView.alpha = 0.6f;
self.backImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
if (_isShow) {
_tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeTapping)];
_tap.delegate = self;
_tap.numberOfTapsRequired = 1.0;
[self.backImageView addGestureRecognizer:_tap];
}
}
[[UIApplication sharedApplication].keyWindow addSubview:self.backImageView];
self.transform = CGAffineTransformMakeRotation(-M_1_PI / 2);
// CGRect afterFrame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, (CGRectGetHeight(topVC.view.bounds) - kAlertHeight) * 0.5, kAlertWidth, kAlertHeight);
CGRect afterFrame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, (CGRectGetHeight(topVC.view.bounds) - _contentHeight) * 0.5, kAlertWidth, _contentHeight );
if (timeShow) {
afterFrame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, (CGRectGetHeight(topVC.view.bounds) - kAlertHeightTime) * 0.5, kAlertWidth, kAlertHeightTime);
}
if (_isDynamic) {//[_rightBtn.titleLabel.text isEqualToString:@"更新"]
afterFrame = CGRectMake((CGRectGetWidth(topVC.view.bounds) - kAlertWidth) * 0.5, (CGRectGetHeight(topVC.view.bounds) - (_contentHeight+50*WIDTHRADIUS+_titleHeight)) * 0.5, kAlertWidth, _contentHeight+50*WIDTHRADIUS+_titleHeight);
}
[UIView animateWithDuration:0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.transform = CGAffineTransformMakeRotation(0);
self.frame = afterFrame;
} completion:^(BOOL finished) {
}];
[super willMoveToSuperview:newSuperview];
}
- (void)exChangeOut:(UIView *)changeOutView dur:(CFTimeInterval)dur{
CAKeyframeAnimation * animation;
animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = dur;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.8, 0.8, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.08, 1.08, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values;
animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
[changeOutView.layer addAnimation:animation forKey:nil];
}
- (void)cancle {
[self hide:nil];
}
-(void)clickClose{
[self removeFromSuperviews];
if (self.dismissBlock) {
self.dismissBlock();
}
}
-(void)commitOpinion{
[self hide:nil];
if (self.commitBlock) {
self.commitBlock(self.tvText.text);
}
}
@end```
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)