Нет описания

FKWeixinShareView.m 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. //
  2. // FKWeixinShareView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/4/12.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKWeixinShareView.h"
  9. #define kShareActionBtnTagBase 900
  10. #define kShareContentHeight (IS_IPHONE_X ? 194 : 160)
  11. #define kShareAnimationDuration 0.2f
  12. @interface FKWeixinShareView ()
  13. @property (nonatomic, strong) UIView *contentView;
  14. @property (nonatomic, strong) UIView *bgView;
  15. @property (nonatomic, copy) void (^acitonBlock)(kShareViewActionType type);
  16. @end
  17. @implementation FKWeixinShareView
  18. - (instancetype)initWithFrame:(CGRect)frame{
  19. if (self = [super initWithFrame:frame]) {
  20. [self addAllSubviews];
  21. [self addNotify];
  22. }
  23. return self;
  24. }
  25. - (void)addAllSubviews{
  26. UILabel *titleLabel = ({
  27. UILabel *label = [[UILabel alloc]init];
  28. label.font = [UIFont systemFontOfSize:15];
  29. label.textColor = UIColorFromRGB(0x666666);
  30. label.text = @"分享到";
  31. label;
  32. });
  33. UIView *seperatorLine = ({
  34. UIView *view =[[UIView alloc]init];
  35. view.backgroundColor = UIColorFromRGB(0xe5e5e5);
  36. view;
  37. });
  38. UIImageView *friendImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"share_only_weixin_friend"]];
  39. UIImageView *circleImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"share_only_weixin_circle"]];
  40. UILabel *friendLabel = ({
  41. UILabel *label = [[UILabel alloc]init];
  42. label.textColor = UIColorFromRGB(0x666666);
  43. label.font = [UIFont systemFontOfSize:15];
  44. label.text = @"微信好友";
  45. label;
  46. });
  47. UILabel *circleLabel = ({
  48. UILabel *label = [[UILabel alloc]init];
  49. label.textColor = UIColorFromRGB(0x666666);
  50. label.font = [UIFont systemFontOfSize:15];
  51. label.text = @"微信朋友圈";
  52. label;
  53. });
  54. UIButton *cancelBtn = ({
  55. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  56. [button setImage:[UIImage imageNamed:@"shareCancel"] forState:UIControlStateNormal];
  57. [button addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
  58. button.tag = kShareActionBtnTagBase + 0;
  59. button;
  60. });
  61. UIButton *friendActionBtn = ({
  62. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  63. [button addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
  64. button.tag = kShareActionBtnTagBase + 1;
  65. button;
  66. });
  67. UIButton *circleActionBtn = ({
  68. UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
  69. [button addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
  70. button.tag = kShareActionBtnTagBase + 2;
  71. button;
  72. });
  73. [self addSubview:self.bgView];
  74. [self addSubview:self.contentView];
  75. [self.contentView addSubview:titleLabel];
  76. [self.contentView addSubview:cancelBtn];
  77. [self.contentView addSubview:seperatorLine];
  78. [self.contentView addSubview:friendImgView];
  79. [self.contentView addSubview:circleImgView];
  80. [self.contentView addSubview:friendLabel];
  81. [self.contentView addSubview:circleLabel];
  82. [self.contentView addSubview:friendActionBtn];
  83. [self.contentView addSubview:circleActionBtn];
  84. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  85. make.edges.insets(UIEdgeInsetsZero);
  86. }];
  87. [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.right.bottom.equalTo(self);
  89. make.height.mas_equalTo(kShareContentHeight);
  90. }];
  91. [seperatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.left.right.equalTo(self.contentView);
  93. make.top.mas_equalTo(self.contentView).offset(45);
  94. make.height.mas_equalTo(0.5);
  95. }];
  96. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  97. make.top.mas_equalTo(self.contentView);
  98. make.bottom.equalTo(seperatorLine.mas_top);
  99. make.centerX.mas_equalTo(self.contentView);
  100. }];
  101. [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  102. make.right.mas_equalTo(self.contentView);
  103. make.centerY.equalTo(titleLabel);
  104. make.size.mas_equalTo(CGSizeMake(45, 45));
  105. }];
  106. [friendActionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.top.mas_equalTo(seperatorLine.mas_bottom);
  108. make.left.bottom.equalTo(self.contentView);
  109. make.width.mas_equalTo(circleActionBtn);
  110. }];
  111. [circleActionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  112. make.top.mas_equalTo(seperatorLine.mas_bottom);
  113. make.right.bottom.equalTo(self.contentView);
  114. make.left.mas_equalTo(friendActionBtn.mas_right);
  115. }];
  116. [friendImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  117. make.top.equalTo(friendActionBtn).offset(15);
  118. make.centerX.equalTo(friendActionBtn);
  119. }];
  120. [circleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.top.equalTo(circleActionBtn).offset(15);
  122. make.centerX.equalTo(circleActionBtn);
  123. }];
  124. [friendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  125. make.top.equalTo(friendImgView.mas_bottom).offset(10);
  126. make.centerX.equalTo(friendImgView);
  127. }];
  128. [circleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  129. make.top.equalTo(circleImgView.mas_bottom).offset(10);
  130. make.centerX.equalTo(circleImgView);
  131. }];
  132. }
  133. - (void)dealloc{
  134. [[NSNotificationCenter defaultCenter] removeObserver:self];
  135. }
  136. - (void)addNotify{
  137. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weiXinShareSuccess) name:FK_SHARE_SUCCESS object:nil];
  138. }
  139. - (void)weiXinShareSuccess{
  140. [self dismiss];
  141. }
  142. - (void)clickBgView{
  143. [self dismiss];
  144. }
  145. - (void)clickActionBtn:(UIButton *)sender{
  146. kShareViewActionType type = kShareViewActionTypeNone;
  147. switch (sender.tag) {
  148. case kShareActionBtnTagBase + 0:{
  149. [self dismiss];
  150. return;
  151. }
  152. break;
  153. case kShareActionBtnTagBase + 1:
  154. type = kShareViewActionTypeFriend;
  155. break;
  156. case kShareActionBtnTagBase + 2:
  157. type = kShareViewActionTypeCircle;
  158. break;
  159. default:
  160. break;
  161. }
  162. if (type == kShareViewActionTypeNone) return;
  163. if (self.acitonBlock) self.acitonBlock(type);
  164. }
  165. - (void)showInView:(UIView *)view actionBlock:(void (^)(kShareViewActionType type))action{
  166. if (!view) return;
  167. [self removeFromSuperview];
  168. self.acitonBlock = action;
  169. self.bgView.alpha = 0;
  170. self.contentView.transform = CGAffineTransformMakeTranslation(0, kShareContentHeight);
  171. self.frame = view.bounds;
  172. [view addSubview:self];
  173. WeakSelf(weakSelf);
  174. [UIView animateWithDuration:kShareAnimationDuration animations:^{
  175. weakSelf.bgView.alpha = 1.0f;
  176. weakSelf.contentView.transform = CGAffineTransformIdentity;
  177. } completion:nil];
  178. }
  179. - (void)dismiss{
  180. self.bgView.alpha = 1.0f;
  181. self.contentView.transform = CGAffineTransformIdentity;
  182. WeakSelf(weakSelf);
  183. [UIView animateWithDuration:kShareAnimationDuration animations:^{
  184. weakSelf.bgView.alpha = 0;
  185. weakSelf.contentView.frame = CGRectOffset(weakSelf.contentView.frame, 0, kShareContentHeight);
  186. // weakSelf.contentView.transform = CGAffineTransformMakeTranslation(0, kShareContentHeight);
  187. } completion:^(BOOL finished) {
  188. [weakSelf removeFromSuperview];
  189. }];
  190. }
  191. #pragma mark - property
  192. - (UIView *)contentView{
  193. if (_contentView == nil) {
  194. _contentView = [[UIView alloc]init];
  195. _contentView.backgroundColor = [UIColor whiteColor];
  196. }
  197. return _contentView;
  198. }
  199. - (UIView *)bgView{
  200. if (_bgView == nil) {
  201. _bgView = [[ UIView alloc]init];
  202. _bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  203. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickBgView)];
  204. tap.numberOfTapsRequired = 1;
  205. tap.numberOfTouchesRequired = 1;
  206. [_bgView addGestureRecognizer:tap];
  207. }
  208. return _bgView;
  209. }
  210. @end