HMShareView.m 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. //
  2. // HMShareView.m
  3. // BuguLive
  4. //
  5. // Created by 范东 on 2019/1/2.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "HMShareView.h"
  9. #define kShareViewButtonBaseTag 11
  10. #define kShareViewHeight 150
  11. #define kShareViewHasReportHeight 250
  12. @interface HMShareView ()
  13. @property (nonatomic, strong) UIView *shadowView;
  14. @property (nonatomic, strong) NSMutableArray *dataArray;
  15. @property (nonatomic, strong) UIScrollView *scrollView;
  16. @property (nonatomic, strong) UIButton *reportBtn;
  17. @end
  18. @implementation HMShareView
  19. - (instancetype)initWithFrame:(CGRect)frame{
  20. if ([super initWithFrame:frame]) {
  21. self.backgroundColor = kWhiteColor;
  22. [self initSubview];
  23. }
  24. return self;
  25. }
  26. - (void)initSubview{
  27. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 0, kScreenW, 50)];
  28. [titleLabel setText:ASLocalizedString(@"分享到")];
  29. [titleLabel setFont:[UIFont systemFontOfSize:16]];
  30. [titleLabel setTextAlignment:NSTextAlignmentLeft];
  31. [titleLabel setBackgroundColor:kWhiteColor];
  32. [self addSubview:titleLabel];
  33. if (self.BuguLive.appModel.wx_app_api == 1)
  34. {
  35. [self.dataArray addObject:@"fw_share_circle"];
  36. [self.dataArray addObject:@"fw_share_wechat"];
  37. }
  38. if (self.BuguLive.appModel.qq_app_api == 1)
  39. {
  40. [self.dataArray addObject:@"fw_share_qq"];
  41. [self.dataArray addObject:@"fw_share_qqCircle"];
  42. }
  43. if (self.BuguLive.appModel.sina_app_api == 1)
  44. {
  45. [self.dataArray addObject:@"fw_share_weiBo"];
  46. }
  47. NSArray *titleArray = @[ASLocalizedString(@"朋友圈"),ASLocalizedString(@"微信"),ASLocalizedString(@"微博"),@"QQ",ASLocalizedString(@"QQ空间")];
  48. for (NSInteger i = 0; i < self.dataArray.count; i++) {
  49. UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(20 + i*(50 + 20), 0, 50, 50)];
  50. [button setTag:kShareViewButtonBaseTag + i];
  51. [button setImage:[UIImage imageNamed:self.dataArray[i]] forState:UIControlStateNormal];
  52. [button addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
  53. [self.scrollView addSubview:button];
  54. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, button.bottom, 70, 50)];
  55. titleLabel.text = titleArray[i];
  56. titleLabel.font = [UIFont systemFontOfSize:15];
  57. titleLabel.textAlignment = NSTextAlignmentCenter;
  58. titleLabel.centerX = button.centerX;
  59. [self.scrollView addSubview:titleLabel];
  60. }
  61. [self addSubview:self.scrollView];
  62. self.scrollView.contentSize = CGSizeMake(self.dataArray.count * (50 + 20 ) + 20, self.scrollView.height);
  63. // self.scrollView.centerX = kScreenW / 2;
  64. // UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 150, kScreenW, 50)];
  65. // [cancelBtn setTitle:ASLocalizedString(@"取消分享")forState:UIControlStateNormal];
  66. // [cancelBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
  67. // [cancelBtn.titleLabel setFont:[UIFont systemFontOfSize:16]];
  68. // [cancelBtn addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside];
  69. // [self addSubview:cancelBtn];
  70. [self addSubview:self.reportBtn];
  71. UILabel *reportLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, self.reportBtn.bottom, 70, 50)];
  72. reportLabel.text = ASLocalizedString(@"举报");
  73. reportLabel.font = [UIFont systemFontOfSize:15];
  74. reportLabel.textAlignment = NSTextAlignmentCenter;
  75. reportLabel.centerX = self.reportBtn.centerX;
  76. [self addSubview:reportLabel];
  77. }
  78. - (void)onClick:(UIButton *)sender{
  79. [self hide];
  80. if (self.delegate && [self.delegate respondsToSelector:@selector(clickShareViewBtn:)]) {
  81. NSString *imageName = self.dataArray[sender.tag - kShareViewButtonBaseTag];
  82. if ([imageName equalsString:@"fw_share_qq"]) {
  83. [self.delegate clickShareViewBtn:UMSocialPlatformType_QQ];
  84. }
  85. if ([imageName equalsString:@"fw_share_qqCircle"]) {
  86. [self.delegate clickShareViewBtn:UMSocialPlatformType_Qzone];
  87. }
  88. if ([imageName equalsString:@"fw_share_wechat"]) {
  89. [self.delegate clickShareViewBtn:UMSocialPlatformType_WechatSession];
  90. }
  91. if ([imageName equalsString:@"fw_share_circle"]) {
  92. [self.delegate clickShareViewBtn:UMSocialPlatformType_WechatTimeLine];
  93. }
  94. if ([imageName equalsString:@"fw_share_weiBo"]) {
  95. [self.delegate clickShareViewBtn:UMSocialPlatformType_Sina];
  96. }
  97. }
  98. }
  99. - (void)reportBtnAction{
  100. [self hide];
  101. //点击了举报
  102. if (self.delegate && [self.delegate respondsToSelector:@selector(clickShareViewReportBtn)]) {
  103. [self.delegate clickShareViewReportBtn];
  104. }
  105. }
  106. - (void)show:(UIView *)superView isNeedReport:(BOOL)isNeedReport{
  107. [superView addSubview:self.shadowView];
  108. [superView addSubview:self];
  109. [UIView animateWithDuration:0.25 animations:^{
  110. self.shadowView.alpha = 1;
  111. self.y = kScreenH - (isNeedReport ? kShareViewHasReportHeight : kShareViewHeight);
  112. }];
  113. }
  114. - (void)hide{
  115. [UIView animateWithDuration:0.25 animations:^{
  116. self.shadowView.alpha = 0;
  117. self.y = kScreenH;
  118. } completion:^(BOOL finished) {
  119. [self.shadowView removeFromSuperview];
  120. [self removeFromSuperview];
  121. }];
  122. }
  123. - (NSMutableArray *)dataArray{
  124. if (!_dataArray) {
  125. _dataArray = [[NSMutableArray alloc]init];
  126. }
  127. return _dataArray;
  128. }
  129. - (UIScrollView *)scrollView{
  130. if (!_scrollView) {
  131. _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 50, kScreenW, 100)];
  132. _scrollView.showsHorizontalScrollIndicator = NO;
  133. }
  134. return _scrollView;
  135. }
  136. - (UIView *)shadowView{
  137. if (!_shadowView) {
  138. _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  139. _shadowView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.5];
  140. _shadowView.alpha = 0;
  141. _shadowView.userInteractionEnabled = YES;
  142. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  143. [_shadowView addGestureRecognizer:tap];
  144. }
  145. return _shadowView;
  146. }
  147. - (UIButton *)reportBtn{
  148. if (!_reportBtn) {
  149. _reportBtn = [[UIButton alloc]initWithFrame:CGRectMake(20, 150, 50, 50)];
  150. [_reportBtn setImage:[UIImage imageNamed:@"ss_icon_report"] forState:UIControlStateNormal];
  151. [_reportBtn addTarget:self action:@selector(reportBtnAction) forControlEvents:UIControlEventTouchUpInside];
  152. }
  153. return _reportBtn;
  154. }
  155. /*
  156. // Only override drawRect: if you perform custom drawing.
  157. // An empty implementation adversely affects performance during animation.
  158. - (void)drawRect:(CGRect)rect {
  159. // Drawing code
  160. }
  161. */
  162. @end