BogoSharePopView.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. //
  2. // BogoSharePopView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2020/10/22.
  6. // Copyright © 2020 xfg. All rights reserved.
  7. //
  8. #import "BogoSharePopView.h"
  9. static CGFloat const KShareContaintHeight = 250;
  10. @implementation BogoSharePopView
  11. -(BogoPosterImgView *)topSmView{
  12. if (!_topSmView) {
  13. _topSmView = [[BogoPosterImgView alloc]initWithFrame:CGRectMake(70, kRealValue(131), kRealValue(250), kRealValue(280))];
  14. _topSmView.centerX = kScreenW / 2;
  15. _topSmView.is_Small=YES;
  16. _topSmView.backgroundColor = kWhiteColor;
  17. }
  18. return _topSmView;
  19. }
  20. - (instancetype)init {
  21. self = [super init];
  22. if (self) {
  23. self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.15];
  24. self.frame = [UIScreen mainScreen].bounds;
  25. [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGuesture:)]];
  26. _container = [[UIView alloc] initWithFrame:CGRectMake(10, kScreenH, kScreenW - 20, KShareContaintHeight)];
  27. _container.backgroundColor = kWhiteColor;
  28. _container.clipsToBounds = YES;
  29. _container.layer.cornerRadius = 5;
  30. [self addSubview:_container];
  31. _posterContainerView = [[UIView alloc] initWithFrame:CGRectMake(10, kScreenH, kScreenW - 20, kRealValue(117))];
  32. _posterContainerView.backgroundColor = kWhiteColor;
  33. _posterContainerView.clipsToBounds = YES;
  34. _posterContainerView.layer.cornerRadius = 5;
  35. _posterContainerView.hidden = YES;
  36. [self addSubview:_posterContainerView];
  37. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 11, _container.width, 22)];
  38. label.textAlignment = NSTextAlignmentCenter;
  39. label.numberOfLines = 0;
  40. label.text = NSLocalizedString(ASLocalizedString(@"分享到"), nil);
  41. label.textColor = [UIColor colorWithHexString:@"#333333"];
  42. label.font = [UIFont systemFontOfSize:14];
  43. [_container addSubview:label];
  44. NSArray *Arr = @[@[ASLocalizedString(@"微信好友"),ASLocalizedString(@"微信朋友圈"),ASLocalizedString(@"QQ好友"),ASLocalizedString(@"QQ空间")],@[ASLocalizedString(@"复制链接"),ASLocalizedString(@"生成海报"),ASLocalizedString(@"FaceBook")]];
  45. NSArray *imageArrImage = @[@[@"微信好友",@"微信朋友圈",@"QQ好友",@"QQ空间"],@[@"复制链接",@"生成海报",@"FaceBook"]];
  46. //主分享View
  47. for (int j=0; j<Arr.count; j++) {
  48. NSArray *rowArr=Arr[j];
  49. CGFloat viewWidth = _container.width / 4;
  50. NSArray *rowImageArr=imageArrImage[j];
  51. for (int i=0; i<[rowArr count]; i++) {
  52. CGFloat viewTop = j*kRealValue(85)+kRealValue(35);
  53. ShareItem *item = [[ShareItem alloc] initWithFrame:CGRectMake(i * viewWidth, viewTop, viewWidth, kRealValue(80))];
  54. item.icon.image = [UIImage imageNamed:rowImageArr[i]];
  55. item.label.text = rowArr[i];
  56. item.tag = j*10+i;;
  57. [item addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onItemTap:)]];
  58. [_container addSubview:item];
  59. }
  60. }
  61. //海报分享View
  62. NSArray *posterImgArr = @[ASLocalizedString(@"微信好友"),ASLocalizedString(@"微信朋友圈"),ASLocalizedString(@"QQ好友"),ASLocalizedString(@"QQ空间"),ASLocalizedString(@"保存到相册")];
  63. for (int i=0; i < posterImgArr.count; i++) {
  64. CGFloat viewWidth = _container.width / 5;
  65. CGFloat viewTop = kRealValue(15);
  66. ShareItem *item = [[ShareItem alloc] initWithFrame:CGRectMake(i * viewWidth, viewTop, viewWidth, kRealValue(80))];
  67. item.icon.image = [UIImage imageNamed:posterImgArr[i]];
  68. item.label.text = posterImgArr[i];
  69. item.tag = i;
  70. if (i == 4) {
  71. item.tag = 100 + 4;
  72. }
  73. [item addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onItemTap:)]];
  74. [_posterContainerView addSubview:item];
  75. }
  76. _cancel = [[UIButton alloc] initWithFrame:CGRectMake(10, kScreenH-44-49-20, kScreenW - 20, 44 )];
  77. // [_cancel setTitleEdgeInsets:UIEdgeInsetsMake(-SafeAreaBottomHeight, 0, 0, 0)];
  78. [_cancel addTarget:self action:@selector(dismiss) forControlEvents:UIControlEventTouchUpInside];
  79. [_cancel setTitle:NSLocalizedString(ASLocalizedString(@"取消"), nil) forState:UIControlStateNormal];
  80. [_cancel setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  81. _cancel.titleLabel.font = [UIFont systemFontOfSize:15];
  82. _cancel.backgroundColor = kWhiteColor;
  83. _cancel.clipsToBounds = YES;
  84. _cancel.layer.cornerRadius = 5;
  85. [self addSubview:_cancel];
  86. }
  87. return self;
  88. }
  89. - (void)onItemTap:(UITapGestureRecognizer *)sender{
  90. if (sender.view.tag == 100 + 4) {
  91. [self clickSaveAlbum];
  92. return;
  93. }
  94. if (sender.view.tag >3 && sender.view.tag != 12) {
  95. [self onActionItemTap:sender];
  96. } else {
  97. [self onShareItemTap:sender.view.tag];
  98. }
  99. }
  100. //保存海报到相册
  101. -(void)clickSaveAlbum{
  102. // [[HUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在保存中")];
  103. UIImage *image = [self convertViewToImage:self.topSmView.backImageView];
  104. [self loadImageFinished:image];
  105. }
  106. - (UIImage *)convertViewToImage:(UIView *)view {
  107. UIImage *imageRet = [[UIImage alloc]init];
  108. //UIGraphicsBeginImageContextWithOptions(区域大小, 是否是非透明的, 屏幕密度);
  109. UIGraphicsBeginImageContextWithOptions(view.frame.size, YES, [UIScreen mainScreen].scale);
  110. [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  111. imageRet = UIGraphicsGetImageFromCurrentImageContext();
  112. UIGraphicsEndImageContext();
  113. return imageRet;
  114. }
  115. - (void)loadImageFinished:(UIImage *)image{
  116. UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (__bridge void *)self);
  117. }
  118. - (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
  119. // [[HUDHelper sharedInstance]syncStopLoading];
  120. // [self.shareView hide];
  121. // self.topBgView.imageStr=[UIImage new];
  122. // self.topBgView.hidden=YES;
  123. // [self.topBgView removeFromSuperview];
  124. if (!error) {
  125. [FanweMessage alert:ASLocalizedString(@"成功保存,请到相册中查看")];
  126. }else{
  127. [FanweMessage alert:error.description];
  128. }
  129. NSLog(@"image = %@, error = %@, contextInfo = %@", image, error, contextInfo);
  130. }
  131. - (void)onActionItemTap:(UITapGestureRecognizer *)sender {
  132. if (sender.view.tag == 10) {
  133. UIPasteboard*pasteboard = [UIPasteboard generalPasteboard];
  134. pasteboard.string = self.shareContent;
  135. [BGHUDHelper alert:ASLocalizedString(@"已复制到粘贴板")];
  136. }else if (sender.view.tag == 11){
  137. //两个shareView
  138. _container.hidden = YES;
  139. _posterContainerView.hidden = NO;
  140. _posterContainerView.bottom = self.cancel.top - kRealValue(10);
  141. ShareModel *model = [ShareModel new];
  142. model.share_url = self.shareContent;
  143. self.topSmView.model = model;
  144. self.topSmView.is_Small = YES;
  145. [self addSubview:self.topSmView];
  146. [self bringSubviewToFront:self.topSmView];
  147. }
  148. }
  149. - (void)onShareItemTap:(NSInteger)sender {
  150. UMSocialPlatformType socialPlatformType;
  151. switch (sender) {
  152. case 0:
  153. socialPlatformType = UMSocialPlatformType_WechatSession;
  154. break;
  155. case 1:
  156. socialPlatformType = UMSocialPlatformType_WechatTimeLine;
  157. break;
  158. case 2:
  159. socialPlatformType = UMSocialPlatformType_QQ;
  160. break;
  161. case 3:
  162. socialPlatformType = UMSocialPlatformType_Qzone;
  163. break;
  164. case 12:
  165. socialPlatformType = UMSocialPlatformType_Facebook;
  166. break;
  167. default:
  168. break;
  169. }
  170. ShareModel *SModel = [ShareModel new];
  171. SModel.share_title = ASLocalizedString(@"好友邀请您一起看直播!");
  172. SModel.share_content = ASLocalizedString(@"新鲜、有趣、好玩、精彩......你想要的都在这里!");
  173. SModel.share_url = self.shareContent;
  174. SModel.share_imageUrl = [GlobalVariables sharedInstance].appModel.app_logo;
  175. [[BGUMengShareManager sharedInstance] shareTo:[AppDelegate sharedAppDelegate].topViewController platformType:socialPlatformType shareModel:SModel succ:nil failed:nil];
  176. [self dismiss];
  177. }
  178. - (void)handleGuesture:(UITapGestureRecognizer *)sender {
  179. CGPoint point = [sender locationInView:_container];
  180. if(![_container.layer containsPoint:point]) {
  181. [self dismiss];
  182. return;
  183. }
  184. point = [sender locationInView:_cancel];
  185. if([_cancel.layer containsPoint:point]) {
  186. [self dismiss];
  187. }
  188. }
  189. - (void)show {
  190. UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
  191. [window addSubview:self];
  192. [UIView animateWithDuration:0.15f
  193. delay:0.0f
  194. options:UIViewAnimationOptionCurveEaseOut
  195. animations:^{
  196. CGRect frame = self.container.frame;
  197. frame.origin.y = frame.origin.y - frame.size.height;
  198. self.container.frame = CGRectMake(10, kScreenH-(KShareContaintHeight+10+44+49+20 + 40) + 32.5, kScreenW- 20, KShareContaintHeight);
  199. self.cancel.frame =CGRectMake(10, kScreenH-44-49-20 + 15, kScreenW-20, 44 );
  200. }
  201. completion:^(BOOL finished) {
  202. }];
  203. }
  204. - (void)dismiss {
  205. [UIView animateWithDuration:0.01f
  206. delay:0.0f
  207. options:UIViewAnimationOptionCurveEaseIn
  208. animations:^{
  209. CGRect frame = self.container.frame;
  210. frame.origin.y = frame.origin.y + frame.size.height;
  211. self.container.frame = CGRectMake(10, kScreenH, kScreenW-20, KShareContaintHeight);
  212. self.cancel.frame = CGRectMake(10, kScreenH, kScreenW-20, 44); }
  213. completion:^(BOOL finished) {
  214. [self removeFromSuperview];
  215. }];
  216. }
  217. @end
  218. #pragma Item view
  219. @implementation ShareItem
  220. - (instancetype)initWithFrame:(CGRect)frame {
  221. self = [super initWithFrame:frame];
  222. if (self) {
  223. _icon = [[UIImageView alloc] init];
  224. _icon.image = [UIImage imageNamed:@"iconHomeAllshareCopylink"];
  225. _icon.contentMode = UIViewContentModeScaleToFill;
  226. _icon.userInteractionEnabled = YES;
  227. [self addSubview:_icon];
  228. _label = [[UILabel alloc] init];
  229. _label.text = @"TEXT";
  230. _label.textColor = [UIColor colorWithHexString:@"#666666"];
  231. _label.font = [UIFont systemFontOfSize:12];
  232. _label.textAlignment = NSTextAlignmentCenter;
  233. [self addSubview:_label];
  234. }
  235. return self;
  236. }
  237. -(void)startAnimation:(NSTimeInterval)delayTime {
  238. CGRect originalFrame = self.frame;
  239. self.frame = CGRectMake(CGRectGetMinX(originalFrame), 35, originalFrame.size.width, originalFrame.size.height);
  240. [UIView animateWithDuration:0.9f
  241. delay:delayTime
  242. usingSpringWithDamping:0.5f
  243. initialSpringVelocity:0.0f
  244. options:UIViewAnimationOptionCurveEaseInOut
  245. animations:^{
  246. self.frame = originalFrame;
  247. }
  248. completion:^(BOOL finished) {
  249. }];
  250. }
  251. -(void)layoutSubviews {
  252. [super layoutSubviews];
  253. [self.icon mas_makeConstraints:^(MASConstraintMaker *make) {
  254. make.width.height.mas_equalTo(48);
  255. make.centerX.equalTo(self);
  256. make.top.equalTo(self).offset(10);
  257. }];
  258. [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
  259. make.centerX.equalTo(self);
  260. make.top.equalTo(self.icon.mas_bottom).offset(10);
  261. }];
  262. }
  263. @end