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

来源:互联网 发布:手机淘宝老版本官方 编辑:程序博客网 时间:2024/05/16 19:53

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

-(void)shareClick{

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

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

    shareview.layer.cornerRadius=8;

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

    [UIViewanimateWithDuration:.5animations:^{

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

    }];

    shareview.backgroundColor=[UIColorclearColor];

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


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

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

    topView.backgroundColor=[UIColorwhiteColor];

    topView.layer.cornerRadius=8;

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


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

    UIButton *btn =[MyCtrolcreateBuuttonWithFrame:CGRectMake(0,120, Width-20,35) ImageName:nilTarget:selfAction:@selector(cancebtnlClick)Title:@"取消"];

    btn.layer.cornerRadius=8;

    btn.backgroundColor=[UIColorwhiteColor];

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

    

    [shareviewaddSubview:btn];

    [shareviewaddSubview:topView];

    [BGviewaddSubview:shareview];


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

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

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


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

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

        shareBtn.tag=100+i;

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

        labtext.textAlignment=1;

        [shareviewaddSubview:labtext];

        [shareviewaddSubview:shareBtn];

    }

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

}



-(void)cancebtnlClick{

    [shareviewremoveFromSuperview];

}

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

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

    

    NSURL *url =[NSURLURLWithString:shareurl];

    NSMutableDictionary *shareParams = [NSMutableDictionarydictionary];

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

                                     images:imgurl

                                       url:url

                                     title:@"凌猫扫码领券"

                                      type:SSDKContentTypeAuto];

    if(btn.tag==100){

       

        [selfstartSharePlatform:SSDKPlatformSubTypeWechatSessionparameters:shareParams];

    }elseif(btn.tag==101){

        [selfstartSharePlatform:SSDKPlatformSubTypeWechatTimelineparameters:shareParams];

    }

}

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


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

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

    

    [ShareSDKshare:platform parameters:parametersonStateChanged:^(SSDKResponseState state,NSDictionary *userData, SSDKContentEntity *contentEntity,NSError *error) {

        

        switch (state) {

            caseSSDKResponseStateSuccess:

            {

                [BGviewremoveFromSuperview];

                break;

            }

            caseSSDKResponseStateCancel:

            {

               [BGviewremoveFromSuperview];

                break;

            }

            default:

                break;

        }

    }];

}



阅读全文
0 0
原创粉丝点击