123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- //
- // FKWeixinShareView.m
- // FirstLink
- //
- // Created by jack on 16/4/12.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKWeixinShareView.h"
- #define kShareActionBtnTagBase 900
- #define kShareContentHeight (IS_IPHONE_X ? 194 : 160)
- #define kShareAnimationDuration 0.2f
- @interface FKWeixinShareView ()
- @property (nonatomic, strong) UIView *contentView;
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, copy) void (^acitonBlock)(kShareViewActionType type);
- @end
- @implementation FKWeixinShareView
- - (instancetype)initWithFrame:(CGRect)frame{
- if (self = [super initWithFrame:frame]) {
- [self addAllSubviews];
- [self addNotify];
- }
- return self;
- }
- - (void)addAllSubviews{
-
- UILabel *titleLabel = ({
- UILabel *label = [[UILabel alloc]init];
- label.font = [UIFont systemFontOfSize:15];
- label.textColor = UIColorFromRGB(0x666666);
- label.text = @"分享到";
- label;
- });
-
- UIView *seperatorLine = ({
- UIView *view =[[UIView alloc]init];
- view.backgroundColor = UIColorFromRGB(0xe5e5e5);
- view;
- });
-
- UIImageView *friendImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"share_only_weixin_friend"]];
- UIImageView *circleImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"share_only_weixin_circle"]];
-
- UILabel *friendLabel = ({
- UILabel *label = [[UILabel alloc]init];
- label.textColor = UIColorFromRGB(0x666666);
- label.font = [UIFont systemFontOfSize:15];
- label.text = @"微信好友";
- label;
- });
-
- UILabel *circleLabel = ({
- UILabel *label = [[UILabel alloc]init];
- label.textColor = UIColorFromRGB(0x666666);
- label.font = [UIFont systemFontOfSize:15];
- label.text = @"微信朋友圈";
- label;
- });
-
- UIButton *cancelBtn = ({
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button setImage:[UIImage imageNamed:@"shareCancel"] forState:UIControlStateNormal];
- [button addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
- button.tag = kShareActionBtnTagBase + 0;
- button;
- });
-
- UIButton *friendActionBtn = ({
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
- button.tag = kShareActionBtnTagBase + 1;
- button;
- });
-
- UIButton *circleActionBtn = ({
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button addTarget:self action:@selector(clickActionBtn:) forControlEvents:UIControlEventTouchUpInside];
- button.tag = kShareActionBtnTagBase + 2;
- button;
- });
-
- [self addSubview:self.bgView];
- [self addSubview:self.contentView];
- [self.contentView addSubview:titleLabel];
- [self.contentView addSubview:cancelBtn];
- [self.contentView addSubview:seperatorLine];
- [self.contentView addSubview:friendImgView];
- [self.contentView addSubview:circleImgView];
- [self.contentView addSubview:friendLabel];
- [self.contentView addSubview:circleLabel];
- [self.contentView addSubview:friendActionBtn];
- [self.contentView addSubview:circleActionBtn];
-
-
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.insets(UIEdgeInsetsZero);
- }];
-
- [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self);
- make.height.mas_equalTo(kShareContentHeight);
- }];
-
- [seperatorLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.equalTo(self.contentView);
- make.top.mas_equalTo(self.contentView).offset(45);
- make.height.mas_equalTo(0.5);
- }];
-
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.contentView);
- make.bottom.equalTo(seperatorLine.mas_top);
- make.centerX.mas_equalTo(self.contentView);
- }];
-
- [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.mas_equalTo(self.contentView);
- make.centerY.equalTo(titleLabel);
- make.size.mas_equalTo(CGSizeMake(45, 45));
- }];
-
- [friendActionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(seperatorLine.mas_bottom);
- make.left.bottom.equalTo(self.contentView);
- make.width.mas_equalTo(circleActionBtn);
- }];
-
- [circleActionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(seperatorLine.mas_bottom);
- make.right.bottom.equalTo(self.contentView);
- make.left.mas_equalTo(friendActionBtn.mas_right);
- }];
-
- [friendImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(friendActionBtn).offset(15);
- make.centerX.equalTo(friendActionBtn);
- }];
-
- [circleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(circleActionBtn).offset(15);
- make.centerX.equalTo(circleActionBtn);
- }];
-
- [friendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(friendImgView.mas_bottom).offset(10);
- make.centerX.equalTo(friendImgView);
- }];
-
- [circleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(circleImgView.mas_bottom).offset(10);
- make.centerX.equalTo(circleImgView);
- }];
-
- }
- - (void)dealloc{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)addNotify{
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weiXinShareSuccess) name:FK_SHARE_SUCCESS object:nil];
- }
- - (void)weiXinShareSuccess{
- [self dismiss];
- }
- - (void)clickBgView{
- [self dismiss];
- }
- - (void)clickActionBtn:(UIButton *)sender{
-
- kShareViewActionType type = kShareViewActionTypeNone;
-
- switch (sender.tag) {
- case kShareActionBtnTagBase + 0:{
- [self dismiss];
- return;
- }
- break;
- case kShareActionBtnTagBase + 1:
- type = kShareViewActionTypeFriend;
- break;
- case kShareActionBtnTagBase + 2:
- type = kShareViewActionTypeCircle;
- break;
- default:
- break;
- }
-
- if (type == kShareViewActionTypeNone) return;
- if (self.acitonBlock) self.acitonBlock(type);
- }
- - (void)showInView:(UIView *)view actionBlock:(void (^)(kShareViewActionType type))action{
-
- if (!view) return;
-
- [self removeFromSuperview];
-
- self.acitonBlock = action;
- self.bgView.alpha = 0;
- self.contentView.transform = CGAffineTransformMakeTranslation(0, kShareContentHeight);
-
- self.frame = view.bounds;
- [view addSubview:self];
-
- WeakSelf(weakSelf);
- [UIView animateWithDuration:kShareAnimationDuration animations:^{
- weakSelf.bgView.alpha = 1.0f;
- weakSelf.contentView.transform = CGAffineTransformIdentity;
- } completion:nil];
- }
- - (void)dismiss{
- self.bgView.alpha = 1.0f;
- self.contentView.transform = CGAffineTransformIdentity;
- WeakSelf(weakSelf);
- [UIView animateWithDuration:kShareAnimationDuration animations:^{
- weakSelf.bgView.alpha = 0;
- weakSelf.contentView.frame = CGRectOffset(weakSelf.contentView.frame, 0, kShareContentHeight);
- // weakSelf.contentView.transform = CGAffineTransformMakeTranslation(0, kShareContentHeight);
- } completion:^(BOOL finished) {
- [weakSelf removeFromSuperview];
- }];
-
- }
- #pragma mark - property
- - (UIView *)contentView{
- if (_contentView == nil) {
- _contentView = [[UIView alloc]init];
- _contentView.backgroundColor = [UIColor whiteColor];
- }
- return _contentView;
- }
- - (UIView *)bgView{
- if (_bgView == nil) {
- _bgView = [[ UIView alloc]init];
- _bgView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(clickBgView)];
- tap.numberOfTapsRequired = 1;
- tap.numberOfTouchesRequired = 1;
-
- [_bgView addGestureRecognizer:tap];
- }
- return _bgView;
- }
- @end
|