123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- //
- // FKShareView.m
- // FirstLink
- //
- // Created by jack on 15/12/30.
- // Copyright © 2015年 FirstLink. All rights reserved.
- //
- #import "FKShareView.h"
- #import "FKRedPacketRequest.h"
- #import "FKRedPacketReform.h"
- #import "FKTargetConfigUtil.h"
- #define kShareActionBtnTagBase 900
- #define kShareContentHeight 310
- #define kShareAnimationDuration 0.2f
- int const FKRewardRequestDetail = 1001;
- @interface FKShareView ()
- <FLNetworkDelegate>
- @property (nonatomic, strong) UIImageView *headerImgView;
- @property (nonatomic, strong) UILabel *rewardLabel;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UIView *contentView;
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UIView *actionView;
- @property (nonatomic, strong) UIView *middleLine;
- @property (nonatomic, strong) UIButton *shareQuestionBtn;
- @property (nonatomic, copy) void (^acitonBlock)(kShareViewActionType type, FKShareView *shareView);
- @end
- @implementation FKShareView
- - (instancetype)initWithLogin:(BOOL)islogin {
- self = [super init];
-
- if (islogin) {
- [self layoutWithLogin];
- [self addNotify];
- } else {
- [self layoutNotLogin];
- [self addNotify];
- }
- return self;
- }
- - (instancetype)init{
- if (self = [super init]) {
- [self layoutWithLogin];
- [self addNotify];
- }
- return self;
- }
- #pragma mark - Response
- - (void)networkDidSuccessResponse:(NSDictionary *)response identify:(int)identify header:(MSGHeader *)header {
- if ([header.code intValue] == RESPONSE_MSG_NORMAL) {
- if (identify == FKRewardRequestDetail){
- NSString *rewardText = [FKRedPacketReform parserAwardTipWithDict:response];
- self.rewardLabel.text = rewardText;
- }
- }
- }
- #pragma mark - Layout
- - (void)layoutWithLogin{
- [self addSubview:self.bgView];
- [self addSubview:self.contentView];
- [self.contentView addSubview:self.headerImgView];
- [self.contentView addSubview:self.rewardLabel];
- [self.contentView addSubview:self.titleLabel];
- [self.contentView addSubview:self.actionView];
- [self.contentView addSubview:self.middleLine];
- [self.contentView addSubview:self.shareQuestionBtn];
- [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(IS_IPHONE_X ? 272 : 248);
- }];
-
- [self.headerImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.contentView.mas_top).offset(41);
- make.centerX.equalTo(self.contentView);
- }];
-
- [self.rewardLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.headerImgView.mas_bottom).offset(9);
- make.centerX.equalTo(self.contentView);
- }];
-
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.headerImgView.mas_bottom).offset(30);
- make.centerX.equalTo(self.contentView);
- make.width.mas_equalTo(270);
- }];
-
- [self.shareQuestionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.size.mas_equalTo(CGSizeMake(47, 53));
- make.top.right.equalTo(self.contentView);
- }];
-
- [self.actionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self.contentView);
- make.height.mas_equalTo(IS_IPHONE_X ? 149 : 125);
- }];
-
- [self.middleLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.equalTo(self.actionView);
- make.height.mas_equalTo(0.5);
- }];
- [self layoutActionView];
- }
- - (void)layoutNotLogin {
- [self addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.insets(UIEdgeInsetsZero);
- }];
-
- [self addSubview:self.contentView];
- [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.bottom.equalTo(self);
- make.height.mas_equalTo(IS_IPHONE_X ? 149 : 125);
- }];
-
- [self.contentView addSubview:self.actionView];
- [self.actionView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self.contentView);
- make.left.equalTo(self.contentView).offset(8);
- make.right.equalTo(self.contentView).offset(-8);
- make.height.mas_equalTo(IS_IPHONE_X ? 149 : 125);
- }];
-
- [self layoutActionView];
- }
- - (void)layoutActionView{
-
- UIButton *wxFriendBtn = [self commonActionBtnWithTag:1 + kShareActionBtnTagBase];
- UIButton *wxCircelBtn = [self commonActionBtnWithTag:2 + kShareActionBtnTagBase];
- UIButton *weiBoBtn = [self commonActionBtnWithTag:3 + kShareActionBtnTagBase];
- UIButton *qqZoneBtn = [self commonActionBtnWithTag:4 + kShareActionBtnTagBase];
- UIButton *copyURLBtn = [self commonActionBtnWithTag:5 + kShareActionBtnTagBase];
-
- [self.actionView addSubview:wxFriendBtn];
- [self.actionView addSubview:wxCircelBtn];
- [self.actionView addSubview:weiBoBtn];
- [self.actionView addSubview:qqZoneBtn];
- [self.actionView addSubview:copyURLBtn];
-
- [wxFriendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.bottom.equalTo(self.actionView);
- make.width.mas_equalTo(weiBoBtn);
- }];
-
- [wxCircelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.equalTo(self.contentView);
- make.left.equalTo(wxFriendBtn.mas_right);
- make.width.mas_equalTo(wxFriendBtn);
- }];
-
- [weiBoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.equalTo(self.contentView);
- make.left.equalTo(wxCircelBtn.mas_right);
- make.width.mas_equalTo(wxCircelBtn);
- }];
-
- [qqZoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.equalTo(self.contentView);
- make.left.equalTo(weiBoBtn.mas_right);
- make.width.mas_equalTo(weiBoBtn);
- }];
-
- [copyURLBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.equalTo(self.contentView);
- make.left.equalTo(qqZoneBtn.mas_right);
- make.right.equalTo(self.actionView);
- make.width.mas_equalTo(qqZoneBtn);
- }];
-
- [self layoutActionAreaWithBtn:wxFriendBtn img:@"share_weixin_friend" title:@"微信好友"];
- [self layoutActionAreaWithBtn:wxCircelBtn img:@"share_weixin_circle" title:@"朋友圈"];
- [self layoutActionAreaWithBtn:weiBoBtn img:@"share_to_weibo" title:@"新浪微博"];
- [self layoutActionAreaWithBtn:qqZoneBtn img:@"share_to_qqZone" title:@"QQ空间"];
- [self layoutActionAreaWithBtn:copyURLBtn img:@"share_url_copy_icon" title:@"复制链接"];
- }
- - (void)dealloc{
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)addNotify{
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(shareSuccess) name:FK_SHARE_SUCCESS object:nil];
- }
- - (void)shareSuccess{
- [self dismiss];
- }
- - (void)clickBgView{
- [self dismiss];
- }
- - (void)clickShareBtn:(UIButton *)sender{
-
- kShareViewActionType type = kShareViewActionTypeNone;
-
- switch (sender.tag) {
- case kShareActionBtnTagBase + 0:
- type = kShareViewActionTypeQuestion;
- break;
- case kShareActionBtnTagBase + 1:
- type = kShareViewActionTypeFriend;
- break;
- case kShareActionBtnTagBase + 2:
- type = kShareViewActionTypeCircle;
- break;
- case kShareActionBtnTagBase + 3:
- type = kShareViewActionTypeWeibo;
- break;
- case kShareActionBtnTagBase + 4:
- type = kShareViewActionTypeQQzone;
- break;
- case kShareActionBtnTagBase + 5:
- type = kShareViewActionTypeURLCopy;
- break;
- default:
- break;
- }
-
- if (type == kShareViewActionTypeNone) return;
-
- WeakSelf(weakSelf);
- if (self.acitonBlock) self.acitonBlock(type, weakSelf);
- }
- - (void)showInView:(UIView *)view actionBlock:(void (^)(kShareViewActionType type, FKShareView *shareView))action{
- [FKRedPacketRequest requestAwardNumber:FKRewardRequestDetail deleagate:self];
-
- 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);
- } completion:^(BOOL finished) {
- if (weakSelf.acitonBlock){
- weakSelf.acitonBlock(kShareViewActionTypeDismiss, weakSelf);
- }
- [weakSelf removeFromSuperview];
- }];
-
- }
- - (void)dismissWithCompletion:(void(^_Nullable)(BOOL finish))completion{
-
- 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);
- } completion:^(BOOL finished) {
- if (completion){
- completion(finished);
- }
- [weakSelf removeFromSuperview];
- }];
- }
- - (UIButton *)commonActionBtnWithTag:(NSInteger)tag{
-
- UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
- [button addTarget:self action:@selector(clickShareBtn:) forControlEvents:UIControlEventTouchUpInside];
- button.tag = tag;
- return button;
- }
- - (void)layoutActionAreaWithBtn:(UIButton *)actionBtn
- img:(NSString *)img
- title:(NSString *)title{
- UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:img]];
- UILabel *titleLabel = ({
- UILabel *label = [[UILabel alloc]init];
- label.font = [UIFont systemFontOfSize:13];
- label.textColor = UIColorFromRGB(0x999999);
- label.text = title;
- label;
- });
-
- [self.actionView insertSubview:imageView belowSubview:actionBtn];
- [self.actionView insertSubview:titleLabel belowSubview:actionBtn];
- [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(self.actionView).offset(25);
- make.centerX.equalTo(actionBtn);
- }];
-
- [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.equalTo(imageView.mas_bottom).offset(10);
- make.centerX.equalTo(imageView);
- }];
- }
- #pragma mark - property
- - (UIImageView *)headerImgView{
- if (_headerImgView == nil) {
- _headerImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"shareHeader"]];
- }
- return _headerImgView;
- }
- - (UILabel *)rewardLabel{
- if (_rewardLabel == nil) {
- _rewardLabel = [[UILabel alloc]init];
- _rewardLabel.textColor = UIColorFromRGB(0xff6362);
- _rewardLabel.font = [UIFont systemFontOfSize:13];
- _rewardLabel.textAlignment = NSTextAlignmentCenter;
- _rewardLabel.numberOfLines = 0;
- }
- return _rewardLabel;
- }
- - (UILabel *)titleLabel{
- if (_titleLabel == nil) {
- _titleLabel = [[UILabel alloc]init];
- _titleLabel.font = [UIFont systemFontOfSize:14];
- _titleLabel.textColor = UIColorFromRGB(0x666666);
- _titleLabel.numberOfLines = 0;
- _titleLabel.textAlignment = NSTextAlignmentCenter;
- _titleLabel.text = [NSString stringWithFormat:@"你的小伙伴通过你分享的链接进到%@你就可以获得相应的积分奖励哦", [FKTargetConfigUtil appName]];
- }
- return _titleLabel;
- }
- - (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;
- }
- - (UIView *)actionView{
- if (_actionView == nil) {
- _actionView = [[UIView alloc]init];
- _actionView.backgroundColor = [UIColor whiteColor];
- }
- return _actionView;
- }
- - (UIView *)middleLine{
- if (_middleLine == nil){
- _middleLine =[[UIView alloc]init];
- _middleLine.backgroundColor = UIColorFromRGB(0xe5e5e5);
- }
- return _middleLine;
- }
- - (UIButton *)shareQuestionBtn{
- if (_shareQuestionBtn == nil) {
- _shareQuestionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _shareQuestionBtn.tag = kShareActionBtnTagBase + 0;
- [_shareQuestionBtn setImage:[UIImage imageNamed:@"shareQuestion"] forState:UIControlStateNormal];
- [_shareQuestionBtn addTarget:self action:@selector(clickShareBtn:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _shareQuestionBtn;
- }
- @end
|