turntableResultView.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // turntableResultView.m
  3. // yunbaolive
  4. //
  5. // Created by IOS1 on 2019/8/24.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "turntableResultView.h"
  9. @interface turntableResultView (){
  10. NSArray *resultArray;
  11. UIImageView *whiteView;
  12. }
  13. @end
  14. @implementation turntableResultView
  15. - (instancetype)initWithResultArray:(NSArray *)array{
  16. self = [super init];
  17. if (self) {
  18. self.frame = CGRectMake(0, 0, _window_width, _window_height);
  19. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
  20. resultArray = array;
  21. [self creatUI];
  22. }
  23. return self;
  24. }
  25. - (void)creatUI{
  26. whiteView = [[UIImageView alloc]initWithFrame:CGRectMake(_window_width*0.1, (_window_height-_window_width*0.88)/2, _window_width*0.8, _window_width*0.75)];
  27. whiteView.layer.cornerRadius = 20.0;
  28. whiteView.layer.masksToBounds = YES;
  29. whiteView.image = [UIImage imageNamed:@"turntable_中奖背景"];
  30. whiteView.userInteractionEnabled = YES;
  31. [self addSubview:whiteView];
  32. UIImageView *titleImgView = [[UIImageView alloc]init];
  33. titleImgView.image = [UIImage imageNamed:getImagename(@"turntable_恭喜中奖")];
  34. [whiteView addSubview:titleImgView];
  35. [titleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.centerX.equalTo(whiteView);
  37. make.centerY.equalTo(whiteView).multipliedBy(0.246);
  38. make.height.equalTo(whiteView).multipliedBy(0.08);
  39. make.width.equalTo(whiteView).multipliedBy(0.257);
  40. }];
  41. CGFloat viewWidth = whiteView.width/4;
  42. UIView *backView = [[UIView alloc]init];
  43. [whiteView addSubview:backView];
  44. [backView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.centerX.equalTo(whiteView);
  46. make.centerY.equalTo(whiteView).multipliedBy(0.857);
  47. make.width.mas_equalTo(resultArray.count > 4 ? viewWidth*4 : viewWidth*resultArray.count);
  48. make.height.mas_equalTo(resultArray.count > 4 ? viewWidth*2 : viewWidth);
  49. }];
  50. [backView layoutIfNeeded];
  51. for (int i = 0; i < resultArray.count; i ++) {
  52. NSDictionary *dic = resultArray[i];
  53. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(viewWidth*(i%4), (i/4) * viewWidth, viewWidth, viewWidth)];
  54. [backView addSubview:view];
  55. UILabel *label = [[UILabel alloc]init];
  56. label.textColor = [UIColor whiteColor];
  57. label.font = [UIFont boldSystemFontOfSize:10];
  58. if ([minstr([dic valueForKey:@"type"]) isEqual:@"1"]) {
  59. label.text = [NSString stringWithFormat:@"%@%@X%@",[common name_coin],minstr([dic valueForKey:@"type_val"]),minstr([dic valueForKey:@"nums"])];
  60. }else{
  61. label.text = [NSString stringWithFormat:@"%@X%@",minstr([dic valueForKey:@"name"]),minstr([dic valueForKey:@"nums"])];
  62. }
  63. label.textAlignment = NSTextAlignmentCenter;
  64. label.numberOfLines = 0;
  65. label.lineBreakMode = NSLineBreakByWordWrapping;
  66. [view addSubview:label];
  67. UIImageView *imageV = [[UIImageView alloc]init];
  68. // imageV.backgroundColor = WPFRandomColor;
  69. [imageV sd_setImageWithURL:[NSURL URLWithString:minstr([dic valueForKey:@"thumb"])]];
  70. imageV.contentMode = UIViewContentModeScaleAspectFit;
  71. [view addSubview:imageV];
  72. [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.center.equalTo(view);
  74. make.width.height.equalTo(view).multipliedBy(0.5);
  75. }];
  76. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  77. // make.left.bottom.width.equalTo(view);
  78. make.top.equalTo(imageV.mas_bottom);
  79. make.centerX.equalTo(view);
  80. make.width.equalTo(view).multipliedBy(0.7);
  81. }];
  82. }
  83. UIButton *sureBtn = [UIButton buttonWithType:0];
  84. [sureBtn setTitle:YZMsg(@"确定") forState:0];
  85. sureBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
  86. [sureBtn addTarget:self action:@selector(sureBtnClick) forControlEvents:UIControlEventTouchUpInside];
  87. [sureBtn setBackgroundImage:[UIImage imageNamed:@"turntable_sure"] forState:0];
  88. [whiteView addSubview:sureBtn];
  89. [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  90. make.centerY.equalTo(whiteView).multipliedBy(1.6857);
  91. make.centerX.equalTo(whiteView);
  92. make.height.equalTo(whiteView).multipliedBy(0.1);
  93. make.width.equalTo(sureBtn.mas_height).multipliedBy(2.5);
  94. }];
  95. UILabel *bottomLabel = [[UILabel alloc]init];
  96. bottomLabel.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
  97. bottomLabel.font = [UIFont systemFontOfSize:10];
  98. bottomLabel.text = YZMsg(@"获得的礼物将存放在礼物背包中");
  99. [whiteView addSubview:bottomLabel];
  100. [bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  101. make.centerX.equalTo(whiteView);
  102. make.top.equalTo(sureBtn.mas_bottom);
  103. make.bottom.equalTo(whiteView);
  104. }];
  105. [whiteView layoutIfNeeded];
  106. sureBtn.layer.cornerRadius = sureBtn.height/2;
  107. sureBtn.layer.masksToBounds = YES;
  108. whiteView.transform = CGAffineTransformMakeScale(0.1,0.1);
  109. [self show];
  110. }
  111. - (void)show{
  112. [UIView animateWithDuration:0.3 animations:^{
  113. whiteView.transform = CGAffineTransformMakeScale(1,1);
  114. }];
  115. }
  116. - (void)sureBtnClick{
  117. [UIView animateWithDuration:0.3 animations:^{
  118. whiteView.transform = CGAffineTransformMakeScale(0.1,0.1);
  119. } completion:^(BOOL finished) {
  120. self.hidden = YES;
  121. [self removeFromSuperview];
  122. }];
  123. }
  124. @end