MONewVersionView.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // MONewVersionView.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2024/2/19.
  6. //
  7. #import "MONewVersionView.h"
  8. @interface MONewVersionView ()
  9. @property (weak, nonatomic) IBOutlet UIView *bgView;
  10. @property (weak, nonatomic) IBOutlet UIButton *updateBtn;
  11. @property (weak, nonatomic) IBOutlet UIButton *closeButton;
  12. /** 是否强制升级 */
  13. @property (nonatomic, assign) BOOL isStrongView;
  14. @property (weak, nonatomic) IBOutlet UILabel *titleLab;
  15. @property (weak, nonatomic) IBOutlet UITextView *contentTextView;
  16. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewWidth;
  17. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgViewHeight;
  18. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *bgImageHeight;
  19. @property (nonatomic, copy) NSString *openUrl;
  20. @end
  21. @implementation MONewVersionView
  22. + (instancetype)moNewVersionView{
  23. return [[[NSBundle mainBundle] loadNibNamed:@"MONewVersionView" owner:self options:nil] firstObject];
  24. }
  25. - (void)awakeFromNib{
  26. [super awakeFromNib];
  27. self.bgView.backgroundColor = [MOTools colorWithHexString:@"#FFFFFF"];
  28. self.bgView.layer.cornerRadius = 12.0;
  29. self.bgView.layer.masksToBounds = YES;
  30. self.updateBtn.layer.cornerRadius = 12;
  31. self.updateBtn.layer.masksToBounds = YES;
  32. NSArray *colorArr = @[kBaseColorLeft,kBaseColorRight];
  33. UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, kScaleWidth(200), 36.0) Colors:colorArr GradientType:0];
  34. [self.updateBtn setBackgroundImage:image forState:UIControlStateNormal];
  35. [self.updateBtn setTitle:NSLocalString(@"mimo_new_version_update") forState:UIControlStateNormal];
  36. [self.updateBtn setFont:[MOTextTools mediumFont:14]];
  37. self.titleLab.font = [MOTextTools mediumFont:19];
  38. self.titleLab.textColor = [MOTools colorWithHexString:@"#FFFFFF"];
  39. [self.contentTextView setFont:[MOTextTools regularFont:15]];
  40. self.contentTextView.textColor = [MOTools colorWithHexString:@"#5C5E66"];
  41. self.bgViewWidth.constant = kScaleWidth(300);
  42. self.bgViewHeight.constant = kScaleWidth(500);
  43. self.bgImageHeight.constant = kScaleWidth(300);
  44. [self.closeButton addTarget:self action:@selector(dismissNewVersionView) forControlEvents:UIControlEventTouchUpInside];
  45. }
  46. - (void)setModel:(MOVersionModel *)model {
  47. _model = model;
  48. if(model.type == 2){
  49. self.isStrongView = YES;
  50. }
  51. self.contentTextView.text = model.desc;
  52. self.openUrl = model.url;
  53. self.titleLab.text = [NSString stringWithFormat:NSLocalString(@"common_version_upgrade_tip"), model.text];
  54. }
  55. - (IBAction)closeBtnClick:(id)sender {
  56. [self dismissNewVersionView];
  57. }
  58. - (IBAction)updateBtnClick:(id)sender {
  59. if(self.openUrl.length == 0){
  60. return;
  61. }
  62. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:self.openUrl]])
  63. {
  64. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.openUrl]];
  65. }
  66. }
  67. - (void)showNewVersionView//界面显示动画
  68. {
  69. UIWindow *keyWindow = [[UIApplication sharedApplication] delegate].window;
  70. [keyWindow addSubview:self];
  71. self.frame = CGRectMake(0.0, 0.0, SCREENWIDTH, SCREENHEIGHT);
  72. //动画效果
  73. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  74. self.bgView.alpha = 0;
  75. [UIView animateWithDuration:0.2 animations:^
  76. {
  77. self.bgView.transform = CGAffineTransformMakeScale(1.0, 1.0);
  78. self.bgView.alpha = 1;
  79. } completion:^(BOOL finished)
  80. {
  81. }];
  82. }
  83. - (void)dismissNewVersionView
  84. {
  85. if(self.isStrongView){
  86. return;
  87. }
  88. [UIView animateWithDuration:0.2 animations:^
  89. {
  90. self.bgView.transform = CGAffineTransformMakeScale(1.3, 1.3);
  91. self.bgView.alpha = 0;
  92. } completion:^(BOOL finished)
  93. {
  94. if (finished)
  95. {
  96. [self removeFromSuperview];
  97. }
  98. }];
  99. }
  100. @end