您的位置:首页 > 其它

模仿快捷分享、从下往上弹出窗口,自定义分享菜单

2017-07-11 18:14 555 查看
shareSDK快捷分享,有集成好的分享菜单栏,很方便好用但是只能是一种样式,总感觉很枯燥无味!我在集成的过程中还发现,快捷分享的成功失败很难拿到回调。所以下面介绍一种自定义的分享菜单以及对平台的定向分享,话不多说上代码,相信很容易看懂!

-(void)shareClick{

//****   从下往上弹出窗口   ******//

    shareview =[MyCtrol
createViewWithFrame:CGRectMake(10,
0, Width-20,
150)];

    shareview.layer.cornerRadius=8;

    shareview.frame =
CGRectMake(0,
Height, Width,
Height/2);

    [UIView
animateWithDuration:.5
animations:^{

        shareview.frame =
CGRectMake(10,
Height-250,
Width-20,
250);

    }];

    shareview.backgroundColor=[UIColor
clearColor];

//****   从下往上弹出窗口   ******//

//****   各平台的分享菜单栏   ******//    

    UIView * topView =[MyCtrol
createViewWithFrame:CGRectMake(0,
0, Width-20,
100)];

    topView.backgroundColor=[UIColor
whiteColor];

    topView.layer.cornerRadius=8;

//****   各平台的分享菜单栏   ******// 

//****   取消弹出的分享菜单栏   ******//     

    UIButton *btn =[MyCtrol
createBuuttonWithFrame:CGRectMake(0,
120, Width-20,
35) ImageName:nil
Target:self
Action:@selector(cancebtnlClick)
Title:@"取消"];

    btn.layer.cornerRadius=8;

    btn.backgroundColor=[UIColor
whiteColor];

//****   取消弹出的分享菜单栏   ******//  

    

    [shareview
addSubview:btn];

    [shareview
addSubview:topView];

    [BGview
addSubview:shareview];

//****   编辑菜单栏对应平台logo以及点击事件触发的定向分享   ******//  

    NSArray *array =@[@"wechat@2x",@"pengyouquan@2x"];

    NSArray *array1 =@[@"微信",@"朋友圈"];

    for(int i =0 ;i<2
;i++){

        UIButton *shareBtn = [MyCtrol
createBuuttonWithFrame:CGRectMake(Width/7+Width/2.08*i,
10, Width/5.35,
Width/5.35)
ImageName:array[i]
Target:self
Action:@selector(sharebtnClick:)
Title:nil];

        shareBtn.tag=100+i;

        UILabel *labtext =[MyCtrol
createLabelWithFrame:CGRectMake(Width/7+Width/2.08*i,
80, Width/5.35,
20) Font:12
Text:array1[i]];

        labtext.textAlignment=1;

        [shareview
addSubview:labtext];

        [shareview
addSubview:shareBtn];

    }

//****   取消弹出的分享菜单栏   ******//      

}

-(void)cancebtnlClick{

    [shareview
removeFromSuperview];

}

//********设置分享参数************

-(void)sharebtnClick:(UIButton *)btn{

    

    NSURL *url =[NSURL
URLWithString:shareurl];

    NSMutableDictionary *shareParams = [NSMutableDictionary
dictionary];

    [shareParams
SSDKSetupShareParamsByText:@"凌猫停车扫码领券,分享有礼!"

                                    
images:imgurl

                                       
url:url

                                     
title:@"凌猫扫码领券"

                                      
type:SSDKContentTypeAuto];

    if(btn.tag==100){

       

        [self
startSharePlatform:SSDKPlatformSubTypeWechatSession
parameters:shareParams];

    }else
if(btn.tag==101){

        [self
startSharePlatform:SSDKPlatformSubTypeWechatTimeline
parameters:shareParams];

    }

}
//********设置分享参数************

//********定向分享到对应平台(微信好友,朋友圈)************

-(void)startSharePlatform:(SSDKPlatformType)platform parameters:(NSMutableDictionary
*)parameters{

    

    [Sha
b59d
reSDK
share:platform parameters:parameters
onStateChanged:^(SSDKResponseState state,
NSDictionary *userData,
SSDKContentEntity *contentEntity,
NSError *error) {

        

        switch (state) {

            case
SSDKResponseStateSuccess:

            {

                [BGview
removeFromSuperview];

                break;

            }

            case
SSDKResponseStateCancel:

            {

               [BGview
removeFromSuperview];

                break;

            }

            default:

                break;

        }

    }];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息