YBAnchorPKAlert.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // YBAnchorPKAlert.m
  3. // yunbaolive
  4. //
  5. // Created by Boom on 2018/11/29.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "YBAnchorPKAlert.h"
  9. #import "XLCircleProgress.h"
  10. @implementation YBAnchorPKAlert{
  11. BOOL isStart;
  12. XLCircleProgress *circle;
  13. UIView *whiteView;
  14. int count;
  15. NSTimer *timer;
  16. }
  17. - (instancetype)initWithFrame:(CGRect)frame andIsStart:(BOOL)start{
  18. self = [super initWithFrame:frame];
  19. self.layer.cornerRadius = 5;
  20. self.layer.masksToBounds = YES;
  21. isStart = start;
  22. count = 10;
  23. if (self) {
  24. [self creatUI];
  25. }
  26. return self;
  27. }
  28. - (void)creatUI{
  29. if (isStart) {
  30. self.backgroundColor = [UIColor clearColor];
  31. circle = [[XLCircleProgress alloc]initWithFrame:CGRectMake(self.width/2-35, 0, 70, 70)];
  32. circle.percentLabel.text = @"10";
  33. circle.percentLabel.textColor = [UIColor blackColor]; //[UIColor whiteColor];
  34. circle.progress = 1;
  35. [self addSubview:circle];
  36. }else{
  37. self.backgroundColor = [UIColor whiteColor];
  38. UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.width, self.height/34*9)];
  39. label.text = YZMsg(@"对方发起PK");
  40. label.textAlignment = NSTextAlignmentCenter;
  41. label.font = [UIFont systemFontOfSize:13];
  42. [self addSubview:label];
  43. circle = [[XLCircleProgress alloc]initWithFrame:CGRectMake(self.width/2-self.height/34*7, label.bottom, self.height/34*14, self.height/34*14)];
  44. circle.percentLabel.text = @"10";
  45. circle.percentLabel.textColor = [UIColor blackColor];
  46. circle.progress = 1;
  47. [self addSubview:circle];
  48. NSArray *arr = @[YZMsg(@"拒绝"),YZMsg(@"接受")];
  49. for (int i = 0; i < arr.count; i++) {
  50. UIButton *btn = [UIButton buttonWithType:0];
  51. btn.frame = CGRectMake(i*self.width/2, self.height/34*26, self.width/2, self.height/34*8);
  52. btn.tag = 1000+i;
  53. [btn setTitle:arr[i] forState:0];
  54. if (i == 0) {
  55. [btn setBackgroundColor:RGB_COLOR(@"#2889f7", 1)];
  56. }else{
  57. [btn setBackgroundColor:RGB_COLOR(@"#f93232", 1)];
  58. }
  59. btn.titleLabel.font = [UIFont systemFontOfSize:15];
  60. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  61. [self addSubview:btn];
  62. }
  63. }
  64. if (!timer) {
  65. timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(daojishi) userInfo:nil repeats:YES];
  66. }
  67. }
  68. - (void)daojishi{
  69. count -- ;
  70. circle.progress = count/10.00;
  71. if (count > 0) {
  72. circle.percentLabel.text = [NSString stringWithFormat:@"%d",count];
  73. }else{
  74. [timer invalidate];
  75. timer = nil;
  76. if (self.anchorPkEvent) {
  77. self.anchorPkEvent(PkAlertType_TimeOut);
  78. }
  79. }
  80. }
  81. - (void)btnClick:(UIButton *)sender{
  82. [timer invalidate];
  83. timer = nil;
  84. if (sender.tag == 1000) {
  85. if (self.anchorPkEvent) {
  86. self.anchorPkEvent(PkAlertType_unAgree);
  87. }
  88. }else{
  89. if (self.anchorPkEvent) {
  90. self.anchorPkEvent(PkAlertType_Agree);
  91. }
  92. }
  93. }
  94. - (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
  95. UIView *hitView = [super hitTest:point withEvent:event];
  96. if(hitView == self){
  97. return nil;
  98. }
  99. return hitView;
  100. }
  101. - (void)removeTimer{
  102. if (timer) {
  103. [timer invalidate];
  104. timer = nil;
  105. }
  106. }
  107. @end