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.
126 lines
5.5 KiB
126 lines
5.5 KiB
// |
|
// WCUpVersionView.m |
|
// neutralWatch |
|
// |
|
// Created by WeiChaoZheng on 2018/1/25. |
|
// Copyright © 2018年 xTT. All rights reserved. |
|
// |
|
|
|
#import "WCUpVersionView.h" |
|
|
|
@interface WCUpVersionView () |
|
@property (nonatomic,strong) UIButton * closeButton; |
|
@property (nonatomic,strong) UIButton * upVersionButton; |
|
@end |
|
|
|
@implementation WCUpVersionView |
|
|
|
-(instancetype)initWithNewUpversionAlertViewWithSetVersion:(NSString *)version Content:(NSString *)content{ |
|
self = [[WCUpVersionView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)]; |
|
if (self) { |
|
UIWindow *window = [UIApplication sharedApplication].keyWindow; |
|
if(window){ |
|
UIView *view = [[UIView alloc] initWithFrame:self.frame]; |
|
view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6]; |
|
[window addSubview:view]; |
|
[view addSubview: self]; |
|
|
|
CGFloat viewW = 250* ScreenWidth/375; |
|
if(viewW < 250){ |
|
viewW = 250; |
|
} |
|
CGFloat viewH = 300* ScreenHeight/667; |
|
if(viewH < 300){ |
|
viewH = 300; |
|
} |
|
|
|
UIView * contentView = [[UIView alloc] initWithFrame:CGRectMake((ScreenWidth-viewW)/2, (ScreenHeight-viewH)/2, viewW, viewH)]; |
|
[self addSubview:contentView]; |
|
contentView.backgroundColor = [UIColor whiteColor]; |
|
contentView.layer.cornerRadius = 5; |
|
contentView.layer.masksToBounds = YES; |
|
// |
|
//背景图片 |
|
UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(contentView.frame.origin.x, contentView.frame.origin.y-25, viewW, 106+23)]; |
|
[self addSubview:backImage]; |
|
[backImage setImage:[UIImage imageNamed:@"img_updated"]]; |
|
//标题文字框 |
|
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 106+10, viewW, 21)]; |
|
[contentView addSubview: titleLabel]; |
|
titleLabel.textAlignment = 1; |
|
titleLabel.font = [UIFont systemFontOfSize:17]; |
|
titleLabel.text = [NSString stringWithFormat:@"版本更新V%@",version]; |
|
|
|
//更新按钮的 高度 |
|
CGFloat btnHeight = 36; |
|
//文字框 |
|
UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(35, 106+10+21+8, viewW-70, (viewH - btnHeight - 15 - 8)-(106+10+21+8))]; |
|
[contentView addSubview:contentLabel]; |
|
contentLabel.textColor = [UIColor lightGrayColor]; |
|
contentLabel.font = [UIFont systemFontOfSize:15]; |
|
contentLabel.text = content; |
|
contentLabel.numberOfLines = 0; |
|
|
|
//按钮 |
|
_upVersionButton = [UIButton buttonWithType:UIButtonTypeSystem]; |
|
[contentView addSubview:_upVersionButton]; |
|
|
|
_upVersionButton.frame = CGRectMake((viewW-120)/2, viewH - btnHeight - 15, 120, btnHeight); |
|
_upVersionButton.titleLabel.font = [UIFont systemFontOfSize:15]; |
|
_upVersionButton.backgroundColor = mainColor; |
|
_upVersionButton.layer.cornerRadius = btnHeight/2.0; |
|
_upVersionButton.layer.masksToBounds = YES; |
|
[_upVersionButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
|
[_upVersionButton setTitle:@"立即更新" forState:UIControlStateNormal]; |
|
[_upVersionButton addTarget:self action:@selector(upVersionAction) forControlEvents:UIControlEventTouchUpInside]; |
|
|
|
//close 按钮 添加在 view 上面 |
|
_closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
|
CGFloat closeButtonWH = 30; |
|
[self addSubview:_closeButton]; |
|
_closeButton.frame = CGRectMake(ScreenWidth-contentView.frame.origin.x-closeButtonWH, contentView.frame.origin.y-20-closeButtonWH, closeButtonWH, closeButtonWH); |
|
[_closeButton setImage:[UIImage imageNamed:@"icon_cancel"] forState:UIControlStateNormal]; |
|
[_closeButton addTarget:self action:@selector(closeWindow) forControlEvents:UIControlEventTouchUpInside]; |
|
[self addSubview:_closeButton]; |
|
//添加个弹性动画 |
|
|
|
[UIView animateWithDuration:1 delay:0 usingSpringWithDamping:0.3 initialSpringVelocity:0.3 options:UIViewAnimationOptionLayoutSubviews animations:^{ |
|
self.transform = CGAffineTransformIdentity; |
|
} completion:^(BOOL finished) { |
|
|
|
}]; |
|
|
|
|
|
} |
|
} |
|
return self; |
|
} |
|
|
|
-(void)closeWindow{ |
|
|
|
if (self.isforceUpdate) { |
|
//提示更新 |
|
LGAlertView *alertView = [[LGAlertView alloc] initWithTitle:@"注意" message:@"取消更新将会退出应用,确认取消更新吗?" style:LGAlertViewStyleAlert buttonTitles:@[@"取消"] cancelButtonTitle:@"确定" destructiveButtonTitle:nil actionHandler:^(LGAlertView *alertView, NSString *title, NSUInteger index) { |
|
|
|
} cancelHandler:^(LGAlertView *alertView){ |
|
exit(0); |
|
} destructiveHandler:nil]; |
|
[alertView showAnimated:YES completionHandler:nil]; |
|
}else{ |
|
if(self){ |
|
[UIView animateWithDuration:0.2 animations:^{ |
|
self.transform = CGAffineTransformMakeScale(0.8, 0.8); |
|
} completion:^(BOOL finished) { |
|
[[self superview] removeFromSuperview]; |
|
}]; |
|
|
|
} |
|
} |
|
} |
|
-(void)upVersionAction{ |
|
if(self.upVersionBlock){ |
|
self.upVersionBlock(); |
|
} |
|
} |
|
|
|
@end
|
|
|