热更新demo

imageShareContent.m 12KB

    // // imageShareContent.m // ThePaperBase // // Created by YoungLee on 15/11/12. // Copyright © 2015年 scar1900. All rights reserved. // #define shareBtnTag 3200 #import "imageShareContent.h" @interface imageShareContent (){ CGFloat iconPadding; CGFloat iconWidthAndHeight; CGFloat iconBtnHeight; CGFloat contentHeight; CGFloat iconBtnPadding; } @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UIImageView *snapView; @property(nonatomic, strong)UIButton* senderButton; @property(nonatomic, strong)NSMutableArray *shareBtnList; @end @implementation imageShareContent @synthesize snapView; @synthesize delegate; @synthesize senderButton; @synthesize shareBtnList; @synthesize contentBO; @synthesize shareImg; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor clearColor]; [self addSubview:self.backView]; self.clipsToBounds = YES; // if (IS_IPHONE_6P) { // iconPadding = 40; // }else if (IS_IPHONE_6){ // iconPadding = 43; // }else { // iconPadding = 30; // } iconPadding = 20; iconWidthAndHeight = (rect_screen.size.width-6*iconPadding)/5; iconBtnHeight = iconWidthAndHeight + 13/2 + 16; iconBtnPadding = iconPadding - 13; contentHeight = 2*iconPadding + iconBtnHeight; [self initShareBtnListAndLabel]; [self addShareBtnInContent]; } return self; } - (void)presentShareContentInView:(UIView*)view sender:(id)sender{ [[UIApplication sharedApplication] beginIgnoringInteractionEvents]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)]; self.senderButton = sender; self.senderButton.selected = YES; self.snapView = nil; UIToolbar *toolBar = [[UIToolbar alloc]init]; if ([toolBar respondsToSelector:@selector(setBarTintColor:)]) { self.snapView = [[UIImageView alloc]initWithFrame:self.bounds]; self.backView.backgroundColor = [UIColor clearColor]; self.snapView.userInteractionEnabled = YES; self.snapView.image = customLightDarkBlurSnapshotFromView(view).image; self.snapView.alpha = 0; } toolBar = nil; [UIView animateWithDuration:0.25 animations:^{ if (self.snapView) { [self addSubview:snapView]; self.snapView.alpha = 1; [self.snapView addGestureRecognizer:tap]; }else { self.backView.alpha = 0.8; [self.backView addGestureRecognizer:tap]; } [view addSubview:self]; } completion:^(BOOL finished) { [self addSubview:self.shareContentView]; [CoreAnimationEffect animationPushUp:self.shareContentView]; [[UIApplication sharedApplication] endIgnoringInteractionEvents]; }]; } - (UIView *)backView { if (!_backView) { _backView = [[UIView alloc]initWithFrame:self.bounds]; _backView.alpha = 0; _backView.backgroundColor = [UIColor colorWithHexString:@"0x3e3c3d"]; } return _backView; } - (UIView *)shareContentView { if (!_shareContentView) { _shareContentView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetHeight(self.bounds)-contentHeight, CGRectGetWidth(self.bounds), contentHeight)]; _shareContentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; } return _shareContentView; } - (void)tap:(id)sender { [self dismissShareContent]; } - (void)initShareBtnListAndLabel { self.shareBtnList = [NSMutableArray arrayWithCapacity:12]; for (int i=0;i<5;i++) { UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; button.tag = shareBtnTag + i; [self setShareBtn:button tagNum:i]; [self setButtonHiligthAndDisableColor:button]; button.layer.cornerRadius = 2.0f; button.clipsToBounds = YES; // if (i<4) { button.frame = CGRectMake(iconPadding+i*(iconWidthAndHeight+iconPadding), iconPadding, iconWidthAndHeight, iconWidthAndHeight); // }else if (i<8) { // button.frame = CGRectMake(iconPadding+(i-4)*(iconWidthAndHeight+iconPadding), iconPadding+iconBtnHeight+iconBtnPadding, iconWidthAndHeight, iconWidthAndHeight); // }else { // button.frame = CGRectMake(iconPadding+(i-8)*(iconWidthAndHeight+iconPadding), iconPadding+2*iconBtnHeight+2*iconBtnPadding, iconWidthAndHeight, iconWidthAndHeight); // } [self.shareBtnList addObject:button]; } } - (void)setShareBtn:(UIButton*)button tagNum:(int)num{ UIImageView *btnImageView = [[UIImageView alloc]init]; switch (num) { case 0: btnImageView.image = Image(@"login/shareWeChat.png"); [button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x77b14d"]) forState:UIControlStateNormal]; [button addTarget:self action:@selector(weChatShare:) forControlEvents:UIControlEventTouchUpInside]; if (![shareUtil isHaveWeChatClient]) { button.enabled = NO; }else { button.enabled = YES; } break; case 1: btnImageView.image = Image(@"login/shareWeChatFriend.png"); [button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x77b14d"]) forState:UIControlStateNormal]; [button addTarget:self action:@selector(friendGroupShare:) forControlEvents:UIControlEventTouchUpInside]; if (![shareUtil isHaveWeChatClient]) { button.enabled = NO; }else { button.enabled = YES; } break; case 2: btnImageView.image = Image(@"login/shareSinaWeiBo.png"); [button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0xcf803d"]) forState:UIControlStateNormal]; [button addTarget:self action:@selector(sinaShare:) forControlEvents:UIControlEventTouchUpInside]; break; case 3: btnImageView.image = Image(@"login/shareQQZone.png"); [button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0xd7bf37"]) forState:UIControlStateNormal]; [button addTarget:self action:@selector(qzoneShare:) forControlEvents:UIControlEventTouchUpInside]; if (![shareUtil isHaveQQClient]) { button.enabled = NO; }else { button.enabled = YES; } break; case 4: btnImageView.image = Image(@"login/shareQQFriend.png"); [button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x5da3e9"]) forState:UIControlStateNormal]; [button addTarget:self action:@selector(qqShare:) forControlEvents:UIControlEventTouchUpInside]; if (![shareUtil isHaveQQClient]) { button.enabled = NO; }else { button.enabled = YES; } break; default: break; } CGSize size = btnImageView.image.size; [button addSubview:btnImageView]; [btnImageView makeConstraints:^(MASConstraintMaker *make) { make.size.equalTo(size); make.center.equalTo(button.center); }]; } - (void)setButtonHiligthAndDisableColor:(UIButton*)btn { [btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK]) forState:UIControlStateHighlighted]; [btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONDISABLEBACK]) forState:UIControlStateDisabled]; } - (void)addShareBtnInContent { if (self.shareBtnList.count > 0) { [self.shareBtnList enumerateObjectsUsingBlock:^(UIButton* btn, NSUInteger idx, BOOL *stop) { [self.shareContentView addSubview:btn]; UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(btn.center.x-117/4, CGRectGetMaxY(btn.frame)+13/2, 117/2, 16)]; label.font = appFont([iphoneLineSpaceAndParaSpace returnLevel1plus5FontSize], NO); label.textColor = [UIColor colorWithHexString:TextBlack]; label.textAlignment = NSTextAlignmentCenter; switch (idx) { case 0: label.text = @"微信好友"; break; case 1: label.text = @"微信朋友圈"; break; case 2: label.text = @"新浪微博"; break; case 3: label.text = @"QQ空间"; break; case 4: label.text = @"QQ好友"; break; default: break; } CGFloat width = [label sizeThatFits:CGSizeMake(CGFLOAT_MAX, 16)].width; label.frame = CGRectMake(btn.center.x-width/2, CGRectGetMaxY(btn.frame)+13/2, width, 16); [self.shareContentView addSubview:label]; }]; } } - (void)dismissShareContent { self.senderButton.selected = NO; [UIView animateWithDuration:0.25 animations:^{ self.shareContentView.frame = CGRectMake(0, CGRectGetHeight(self.bounds), CGRectGetWidth(self.bounds), CGRectGetHeight(self.shareContentView.bounds)); self.snapView.alpha = 0; self.backView.alpha = 0; } completion:^(BOOL finished) { [self.shareContentView removeFromSuperview]; [self.backView removeFromSuperview]; [self.snapView removeFromSuperview]; [self removeFromSuperview]; if ([self.delegate respondsToSelector:@selector(didDismissShareContent:)]) { [self.delegate didDismissShareContent:self]; } }]; } #pragma mark - share event - (void)weChatShare:(UIButton*)btn { [shareUtil interactionShareWithImage:self.shareImg title:nil comment:nil shareUrl:nil shareStyle:self.sharestyle shareType:weChatSessionShareType completion:nil]; [self dismissShareContent]; } - (void)friendGroupShare:(UIButton*)btn { [shareUtil interactionShareWithImage:self.shareImg title:self.contentBO.name comment:self.contentBO.summary shareUrl:self.contentBO.shareUrl shareStyle:self.sharestyle shareType:weChatTimeLineShareType completion:nil]; [self dismissShareContent]; } - (void)sinaShare:(UIButton*)btn { if(self.contentBO.summary.length >50){ self.contentBO.summary = [self.contentBO.summary substringToIndex:50]; } [shareUtil interactionShareWithImage:self.shareImg title:self.contentBO.name comment:self.contentBO.summary shareUrl:self.contentBO.shareUrl shareStyle:self.sharestyle shareType:sinaWeiBoShareType completion:nil]; [self dismissShareContent]; } - (void)qzoneShare:(UIButton*)btn { [shareUtil interactionShareWithImage:self.shareImg title:@"" comment:@"" shareUrl:self.contentBO.shareUrl shareStyle:self.sharestyle shareType:QQZoneShareType completion:nil]; [self dismissShareContent]; } - (void)qqShare:(UIButton*)btn { [shareUtil interactionShareWithImage:self.shareImg title:nil comment:nil shareUrl:nil shareStyle:self.sharestyle shareType:QQFriendShareType completion:nil]; [self dismissShareContent]; } @end