CommonShareView.m 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //
  2. // RoomShareView.m
  3. // UniversalApp
  4. //
  5. // Created by bogokj on 2019/8/5.
  6. // Copyright © 2019 voidcat. All rights reserved.
  7. //
  8. #import "CommonShareView.h"
  9. @interface CommonShareView ()
  10. @property(nonatomic, strong) UIView *shadowView;
  11. @end
  12. @implementation CommonShareView
  13. - (instancetype)initWithFrame:(CGRect)frame{
  14. if (self = [super initWithFrame:frame]) {
  15. self.backgroundColor = [UIColor colorWithHexString:@"#ffffff"];
  16. [self initSubview];
  17. }
  18. return self;
  19. }
  20. - (void)initSubview{
  21. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 15, self.width, 21)];
  22. titleLabel.textColor = [UIColor colorWithHexString:@"333333"];
  23. titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
  24. titleLabel.textAlignment = NSTextAlignmentCenter;
  25. titleLabel.text = NSLocalizedString(@"分享至",nil);
  26. [self addSubview:titleLabel];
  27. NSArray *titleArray = @[NSLocalizedString(@"微信",nil),NSLocalizedString(@"朋友圈",nil),@"QQ",NSLocalizedString(@"QQ空间",nil),NSLocalizedString(@"保存图片",nil)];
  28. NSArray *imageArray = @[@"邀请_微信",@"邀请_朋友圈",@"邀请_QQ",@"邀请_QQ空间",@"邀请_保存图片"];
  29. NSArray *tagArray = @[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Qzone),@(UMSocialPlatformType_UnKnown)];
  30. CGFloat itemWidth = self.width / 5;
  31. for (NSInteger i = 0; i < imageArray.count; i ++) {
  32. NSInteger row = i / 5;
  33. NSInteger col = i % 5;
  34. CGFloat x = itemWidth * col;
  35. CGFloat y = 51;
  36. QMUIButton *button = [[QMUIButton alloc]initWithFrame:CGRectMake(x, y, itemWidth, 70)];
  37. [button setImagePosition:QMUIButtonImagePositionTop];
  38. [button setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateNormal];
  39. [button setImage:[UIImage imageNamed:imageArray[i]] forState:UIControlStateSelected];
  40. button.tag = kRoomShareViewBaseBtnTag + [tagArray[i] integerValue];
  41. [button setTitle:titleArray[i] forState:UIControlStateNormal];
  42. [button setTitleColor:[UIColor colorWithHexString:@"333333"] forState:UIControlStateNormal];
  43. [button setSpacingBetweenImageAndTitle:5];
  44. [button.titleLabel setFont:[UIFont systemFontOfSize:12]];
  45. [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
  46. [self addSubview:button];
  47. }
  48. // UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 137, self.width, 1)];
  49. // lineView.backgroundColor = [UIColor colorWithHexString:@"#F4F4F4"];
  50. // [self addSubview:lineView];
  51. //
  52. // UIButton *cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 138, self.width, self.height - kTabBarHeight1 - 138)];
  53. // [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
  54. // cancelBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  55. // [cancelBtn setTitleColor:[UIColor colorWithHexString:@"777777"] forState:UIControlStateNormal];
  56. // [cancelBtn addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside];
  57. // [self addSubview:cancelBtn];
  58. }
  59. - (void)buttonAction:(QMUIButton *)sender{
  60. if (self.delegate && [self.delegate respondsToSelector:@selector(shareView:didClickBtn:)]) {
  61. [self.delegate shareView:self didClickBtn:sender];
  62. }
  63. }
  64. - (void)show:(UIView *)superView{
  65. [superView addSubview:self.shadowView];
  66. [superView addSubview:self];
  67. __weak __typeof(self)weakSelf = self;
  68. [UIView animateWithDuration:0.25 animations:^{
  69. __strong __typeof(weakSelf)strongSelf = weakSelf;
  70. strongSelf.frame = CGRectMake(strongSelf.left, kScreenH - strongSelf.height - FD_Top_Height, strongSelf.width, strongSelf.height);
  71. }];
  72. }
  73. - (void)hide{
  74. __weak __typeof(self)weakSelf = self;
  75. [UIView animateWithDuration:0.25 animations:^{
  76. __strong __typeof(weakSelf)strongSelf = weakSelf;
  77. strongSelf.frame = CGRectMake(strongSelf.left, kScreenH - FD_Top_Height, strongSelf.width, strongSelf.height);
  78. } completion:^(BOOL finished) {
  79. __strong __typeof(weakSelf)strongSelf = weakSelf;
  80. [strongSelf.shadowView removeFromSuperview];
  81. [strongSelf removeFromSuperview];
  82. }];
  83. }
  84. - (UIView *)shadowView{
  85. if (!_shadowView) {
  86. _shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
  87. _shadowView.backgroundColor = [kBlackColor colorWithAlphaComponent:0.4];
  88. _shadowView.userInteractionEnabled = YES;
  89. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hide)];
  90. [_shadowView addGestureRecognizer:tap];
  91. }
  92. return _shadowView;
  93. }
  94. @end