ChatMoreView.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //
  2. // ChatMoreView.m
  3. // BuguLive
  4. //
  5. // Created by 朱庆彬 on 2017/8/15.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "ChatMoreView.h"
  9. #define Bt_W 50.0f
  10. #define Bt_H 75.0f
  11. #define Bt_s 15.0f
  12. @interface ButtonIcon : UIButton
  13. @end
  14. @implementation ButtonIcon
  15. - (instancetype)initWithFrame:(CGRect)frame
  16. {
  17. self = [super initWithFrame:frame];
  18. if (self)
  19. {
  20. [self setTitleColor:kGrayColor forState:UIControlStateNormal];
  21. self.titleLabel.font = [UIFont systemFontOfSize:13];
  22. self.titleLabel.textAlignment = NSTextAlignmentCenter;
  23. }
  24. return self;
  25. }
  26. - (CGRect)imageRectForContentRect:(CGRect)contentRect
  27. {
  28. contentRect = CGRectMake(0, 0, 50, 50);
  29. return contentRect;
  30. }
  31. - (CGRect)titleRectForContentRect:(CGRect)contentRect
  32. {
  33. contentRect = CGRectMake(-10, 50 + 5.0f, 70, 25);
  34. return contentRect;
  35. }
  36. @end
  37. @interface ChatMoreView ()
  38. {
  39. ButtonIcon *_albumBtn; //图片
  40. ButtonIcon *_cameraBtn; //拍照
  41. UIView *_backView;
  42. }
  43. @end
  44. @implementation ChatMoreView
  45. - (instancetype)init
  46. {
  47. return [self initWithFrame:CGRectZero];
  48. }
  49. - (instancetype)initWithFrame:(CGRect)frame
  50. {
  51. frame = CGRectMake(0, 0, kScreenW, kChatOtherViewHight);
  52. if (self = [super initWithFrame:frame])
  53. {
  54. self.backgroundColor = kAppGrayColor1;
  55. self.y = kScreenH;
  56. //[self initUI];
  57. }
  58. return self;
  59. }
  60. - (void)setGiftView:(BOOL)hidden
  61. {
  62. [_backView setHidden:hidden];
  63. }
  64. - (void)initWithBtnArray:(NSMutableArray *)array
  65. {
  66. NSLog(@"%lu", (unsigned long) array.count);
  67. CGFloat perPageW = kScreenW;
  68. CGFloat perW = perPageW / 4.0f;
  69. CGFloat perH = 80;
  70. CGFloat xPoint = 20.0f;
  71. CGFloat yPoint = 15;
  72. int nextrow = 0;
  73. int nowrows = 0;
  74. for (int index = 0; index < array.count; index++)
  75. {
  76. NSArray *item = array[index];
  77. ButtonIcon *btn = [[ButtonIcon alloc] initWithFrame:CGRectMake(xPoint, yPoint, perW, perH)];
  78. [btn setTitle:item[0] forState:UIControlStateNormal];
  79. [btn setImage:[UIImage imageNamed:item[1]] forState:UIControlStateNormal];
  80. [btn setTag:1000 + index];
  81. [btn addTarget:self action:@selector(itemBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  82. [self addSubview:btn];
  83. nextrow++;
  84. xPoint += perW;
  85. if (nextrow == 4)
  86. { //4个就换一行
  87. nowrows++;
  88. nextrow = 0;
  89. xPoint = 0 * perPageW+20;
  90. yPoint += perH + 20;
  91. }
  92. }
  93. _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenW, 234)];
  94. _backView.backgroundColor = RGBA(233, 233, 233, 1);
  95. [_backView setHidden:YES];
  96. [self addSubview:_backView];
  97. }
  98. - (void)itemBtnClick:(UIButton *)sender
  99. {
  100. if ([self.delegate respondsToSelector:@selector(chatMoreViewButton:)])
  101. {
  102. [self.delegate chatMoreViewButton:sender.tag];
  103. [self hide];
  104. }
  105. }
  106. #pragma mark - Show And Hide
  107. - (void)show:(UIView *)superView{
  108. // [self requestModel];
  109. [superView addSubview:self.shadowView];
  110. [superView addSubview:self];
  111. self.hidden = NO;
  112. [UIView animateWithDuration:0.25 animations:^{
  113. self.shadowView.alpha = 1;
  114. self.y = kScreenH - self.height;
  115. }];
  116. }
  117. - (void)hide{
  118. self.hidden = YES;
  119. if (self.delegate && [self.delegate respondsToSelector:@selector(clickHide)]) {
  120. [self.delegate clickHide];
  121. }
  122. [UIView animateWithDuration:0.25 animations:^{
  123. self.shadowView.alpha = 0;
  124. self.y = kScreenH;
  125. } completion:^(BOOL finished) {
  126. [self.shadowView removeFromSuperview];
  127. [self removeFromSuperview];
  128. }];
  129. }
  130. - (UIView *)shadowView{
  131. if (!_shadowView) {
  132. _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  133. _shadowView.backgroundColor = kClearColor;
  134. _shadowView.userInteractionEnabled = YES;
  135. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  136. [_shadowView addGestureRecognizer:tap];
  137. }
  138. return _shadowView;
  139. }
  140. @end