文档章节

自定义第三方分享弹出框

萍水相逢OSC
 萍水相逢OSC
发布于 2017/02/10 17:19
字数 910
阅读 25
收藏 0
点赞 0
评论 0

1、首先,可用nib创建一个view(如图):



2、各个分享按钮添加点击事件

//代码中的curViewController
 UIViewController* curViewController = [self topViewControllerForViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
//分段
case 1: //weibo
        {
            [[UMSocialData defaultData].extConfig.sinaData.urlResource setResourceType:UMSocialUrlResourceTypeDefault url:self.href];
            [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina]
                                                               content:[NSString stringWithFormat:@"%@", self.descString]
                                                                 image:self.logoImage
                                                              location:nil
                                                           urlResource:resource
                                                   presentedController:curViewController
                                                            completion:^(UMSocialResponseEntity *response) {
                                                                if (response.responseCode == UMSResponseCodeSuccess) {
                                                                    NSLog(@"分享成功");
                                                                }
                                                            }];
            
            break;
        }
        case 2: //Wechat Timeline
        {
            [UMSocialData defaultData].extConfig.wxMessageType = UMSocialWXMessageTypeWeb;
            [UMSocialData defaultData].extConfig.wechatSessionData.url = self.href;
            [UMSocialData defaultData].extConfig.wechatTimelineData.url = self.href;
            [UMSocialData defaultData].extConfig.title = self.title;
            
            [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatTimeline]
                                                               content:[NSString stringWithFormat:@"%@", self.descString]
                                                                 image:self.logoImage
                                                              location:nil
                                                           urlResource:resource
                                                   presentedController:curViewController
                                                            completion:^(UMSocialResponseEntity *response) {
                                                                NSLog(@"%u",response.responseCode);
                                                                if (response.responseCode == UMSResponseCodeSuccess) {
                                                                    NSLog(@"分享成功");
                                                                }
                                                            }];
            break;
        }
        case 3: //WechatSession
        {
            [UMSocialData defaultData].extConfig.wechatSessionData.url = self.href;
            [UMSocialData defaultData].extConfig.wechatSessionData.title = self.title;
            
            [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToWechatSession]
                                                               content:[NSString stringWithFormat:@"%@", self.descString]
                                                                 image:self.logoImage
                                                              location:nil
                                                           urlResource:resource
                                                   presentedController:curViewController
                                                            completion:^(UMSocialResponseEntity *response) {
                                                                if (response.responseCode == UMSResponseCodeSuccess) {
                                                                    NSLog(@"分享成功");
																}
                                                            }];
            
            break;
        }
        case 4: //qq
        {
            [UMSocialData defaultData].extConfig.qqData.title = self.title;
            [UMSocialData defaultData].extConfig.qqData.url = self.href;
            
            [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToQQ]
                                                               content:[NSString stringWithFormat:@"%@", self.descString]
                                                                 image:self.logoImage
                                                              location:nil
                                                           urlResource:resource
                                                   presentedController:curViewController
                                                            completion:^(UMSocialResponseEntity *response) {
                                                                if (response.responseCode == UMSResponseCodeSuccess) {
                                                                    NSLog(@"分享成功");
                                                                }
                                                            }];
            
            break;
        }
        case 5: //brower
        {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.href]];
            
            break;
        }
        case 6: //copy url
        {
            UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
            pasteboard.string = [NSString stringWithFormat:@"%@", self.href];
            MBProgressHUD *HUD = [Utils createHUD];
            HUD.mode = MBProgressHUDModeCustomView;
            HUD.label.text = @"已复制到剪切板";
            if (self.superview) {
                [self removeFromSuperview];
            }
            [HUD hideAnimated:YES afterDelay:1];
            
            break;
        }
        case 7:  //more
        {
            if (self.superview) {
                [self removeFromSuperview];
            }
            
            UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[[NSString stringWithFormat:@"分享一个很有意思的内容 %@",self.href]] applicationActivities:nil];
            if ([activityViewController respondsToSelector:@selector(popoverPresentationController)]) {
                activityViewController.popoverPresentationController.sourceView = self;
            }

            [curViewController presentViewController:activityViewController animated:YES completion:nil];
            
            break;
        }
        case 8:     //tweet
        {
            if (self.superview) {
                [self removeFromSuperview];
            }
            
            BOOL isOuterIMP = NO;
            if ([_delegate respondsToSelector:@selector(customShareModeWithShareBoard:boardIndexButton:)]) {
                isOuterIMP = [_delegate customShareModeWithShareBoard:self boardIndexButton:button.tag];
            }
            
            if (isOuterIMP) break;
            
            OSCAbout* forwardInfo = [OSCAbout forwardInfoModelWithTitle:self.authordName
                                                                          content:self.descString type:self.aboutType fullWidth:[UIScreen mainScreen].bounds.size.width - 32];
            TweetEditingVC *tweetEditingVC = [[TweetEditingVC alloc] initWithAboutID:self.aboutId aboutType:self.aboutType forwardItem:forwardInfo];
            UINavigationController *tweetEditingNav = [[UINavigationController alloc] initWithRootViewController:tweetEditingVC];
            [curViewController presentViewController:tweetEditingNav animated:YES completion:nil];
            
            break;
        }
- (UIViewController *)topViewControllerForViewController:(UIViewController *)rootViewController {
    if ([rootViewController isKindOfClass:[UINavigationController class]]) {
        UINavigationController *navigationController = (UINavigationController *)rootViewController;
        return [self topViewControllerForViewController:navigationController.visibleViewController];
    }
    
    if (rootViewController.presentedViewController) {
        return [self topViewControllerForViewController:rootViewController.presentedViewController];
    }
    
    return rootViewController;
}

3、"取消"按钮隐藏弹出框:if (self.superview) {  [self removeFromSuperview]; }

4、用UITouch来控制点击背景隐藏弹出框(contentView为背景view):


#pragma mark --- touch handle 
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    _touchTrack = NO;
    UITouch* t = [touches anyObject];
    CGPoint p1 = [t locationInView:_contentView];
    if (!CGRectContainsPoint(_contentView.bounds, p1)) {
        _touchTrack = YES;
    }else{
        [super touchesBegan:touches withEvent:event];
    }
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (_touchTrack) {
        if (self.superview) {
            [self removeFromSuperview];
        }
    }else{
        [super touchesEnded:touches withEvent:event];
    }
}

- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    if (_touchTrack) {
        if (self.superview) {
            [self removeFromSuperview];
        }
    }else{
        [super touchesCancelled:touches withEvent:event];
    }
}

5、便利构造器(当前view)
 

+ (instancetype)shareBoardWithShareType:(InformationType)infomationType
							  withModel:(id)model
{
    OSCShareBoard *curShareBoard = [[[UINib nibWithNibName:@"OSCShareBoard" bundle:nil] instantiateWithOwner:nil options:nil] lastObject];
    [curShareBoard settingShareType:infomationType model:model];
    return curShareBoard;
}

[curShareBoard settingShareType:infomationType model:model];//model有多种类型参数处理

6、设置代理

- (BOOL)customShareModeWithShareBoard:(OSCShareBoard* )shareBoard
                     boardIndexButton:(NSInteger)buttonTag;

7、在.h文件中新建NSObject类型的对象OSCShareManager,初始化,添加外调方法传数据并设置代理方法

@class OSCShareManager;
@protocol OSCShareManagerDelegate <NSObject>

@optional
- (void)shareManagerCustomShareModeWithManager:(OSCShareManager* )shareManager
                         shareBoardIndexButton:(NSInteger)buttonTag;

@end

@interface OSCShareManager : NSObject

+ (instancetype)shareManager;

- (void)showShareBoardWithShareType:(InformationType)infomationType
                          withModel:(id)model;

- (void)hiddenShareBoard;

@property (nonatomic, weak) id <OSCShareManagerDelegate> delegate;

@end

8、在.m中实现OSCShareManager方法

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define SHAREBOARD_HEIGHT curShareBoard.bounds.size.height
#define SHAREBOARD_WIDTH curShareBoard.bounds.size.width

@interface OSCShareManager ()<OSCShareBoardDelegate>
{
	__weak OSCShareBoard* _curShareBoard;
}

@end

@implementation OSCShareManager

static OSCShareManager* _shareManager ;
+ (instancetype)shareManager
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _shareManager = [OSCShareManager new];
    });
    return _shareManager;
}

- (void)showShareBoardWithShareType:(InformationType)infomationType
						  withModel:(id)model
{
    if ([Config getOwnID] == 0) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"NewLogin" bundle:nil];
        NewLoginViewController *loginVC = [storyboard instantiateViewControllerWithIdentifier:@"NewLoginViewController"];
        [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:loginVC animated:YES completion:nil];
        return ;
    }
    
	if (_curShareBoard) { _curShareBoard = nil;}
	
	OSCShareBoard *curShareBoard = [OSCShareBoard shareBoardWithShareType:infomationType withModel:model];
	_curShareBoard = curShareBoard;
	curShareBoard.frame = [UIScreen mainScreen].bounds;
	curShareBoard = curShareBoard;
	curShareBoard.delegate = self;
	
	[[UIApplication sharedApplication].keyWindow addSubview:curShareBoard];
	
	//背景蒙层的动画:alpha值从0.0变化到0.5
	[curShareBoard.bgView setAlpha:0.0];
	[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
		[curShareBoard.bgView setAlpha:0.5];
	} completion:^(BOOL finished) { }];
	
	//分享面板的动画:从底部向上滚动弹出来
	[curShareBoard.contentView setFrame:CGRectMake(0, SCREEN_HEIGHT , SHAREBOARD_WIDTH, SHAREBOARD_HEIGHT )];
	[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveLinear animations:^{
		[curShareBoard.contentView setFrame:CGRectMake(0,SCREEN_HEIGHT - SHAREBOARD_HEIGHT,SHAREBOARD_WIDTH,SHAREBOARD_HEIGHT)];
	} completion:^(BOOL finished) {}];
}

- (void)hiddenShareBoard
{
    if (_curShareBoard.superview) {
        [_curShareBoard removeFromSuperview];
    }
}

#pragma mark --- OSCShareBoardDelegate
- (BOOL)customShareModeWithShareBoard:(OSCShareBoard* )shareBoard
                     boardIndexButton:(NSInteger)buttonTag
{
    if ([_delegate respondsToSelector:@selector(shareManagerCustomShareModeWithManager:shareBoardIndexButton:)]) {
        [_delegate shareManagerCustomShareModeWithManager:self shareBoardIndexButton:buttonTag];
        return YES;
    }
    return NO;
}

@end

9、页面调用该自定义的第三方分享弹出框(activityDetail为字典类型的数据)

OSCShareManager *shareManeger = [OSCShareManager shareManager];
    [shareManeger showShareBoardWithShareType:InformationTypeActivity withModel:_activityDetail];

 

© 著作权归作者所有

共有 人打赏支持
萍水相逢OSC
粉丝 104
博文 16
码字总数 4469
作品 0
深圳
程序员
第三方app分享内容到朋友圈,点击分享后可以弹出登录界面,登陆后没有分享提示框

第三方app分享内容到朋友圈,点击分享后可以弹出登录界面,登陆后没有分享提示框,以下是我的代码: 点击事件里面的代码,在这个类的onCreate里面注册的appid。 String videoUrl = "http://...

圈圈_cheng
2014/07/01
2.9K
1
ZUI 1.2 发布,增加新特性、优化细节、完善文档

前端html5框架ZUI发布1.2正式版本了! 此版本增加了很多新特性,同时修复了大量问题,文档也得到大幅完善。 欢迎大家使用并反馈问题 下载地址1:http://zui.sexy/ 下载地址2:http://git.os...

炒蚕豆吃蹦豆
2014/11/18
4.6K
0
友盟分享UI标题问题

最近在做友盟分享开发,有个问题,选择完分享的平台后(比如选择了QQ的某个好友后),弹出的那个界面可以自定义UI吗,因为想添加一个edittext,做一个“说些什么”的输入框,还有左下角的标题...

deadPool
2016/07/22
40
0
Windows Phone 7 开发小技巧

1.使用Popup来实现自定义的弹出效果。Popup控件弹出的块会一直在屏幕的最前方,所以使用Popup可以实现各种各样的弹出框,并且给了你极大的自定义的空间,很多第三方的弹出框控件的原理其实就...

junwong
2012/02/28
779
0
iOS项目开发框架“完全体”(三)-- 奥义“手里剑”

本个章节进行BaseViewController的讲解,并放出部分源码哦 首先我们在开发一个项目搭建基类框架的时候,BaseViewController是一个非常重要的环节,后面涉及到继承,重写等各种问题,我们该考...

Suneday
2017/11/30
0
0
iOS程序员眼中的客户端免登陆(数据迁移已更新)

2017.01.15 一、前言,为什么要做免登陆 2017年1月9日,蓄势已久的小程序正式上线,着实,张小龙 用完即走 的理念发挥的淋漓尽致,无需下载,扫码可用,用完即走 2017年互联网人口红利结束了...

si1ence
2017/12/14
0
0
js第三方插件(消息 图形)

1、SeaJS 实现JavaScript的模块化开发及加载机制 2、raphaeljs 实现跨浏览器的矢量图形实现方案 3、lhgcore.js 实现消息弹出框、表单验证、日历、下拉框、在线编辑组建 4、ymPrompt.js 实现消...

mingle
2015/11/30
97
0
zhengtianzuo/QtQuickExamples

QtQuickExamples QtQuick相关的技术分享 访问博客CSDN博客 QmlBusyIndicator: Qml自定义等待指示器 QmlCheckBox: Qml自定义复选框 QmlDragDrop: Qml拖放 QmlFace: Qml表情选择框 QmlHyperli...

zhengtianzuo
2017/12/25
0
0
基于MVC的项目框架--MobileProject

MobileProject介绍 MobileProject项目是一个以MVC模式搭建的开源功能集合,基于Objective-C上面进行编写,意在解决新项目对于常见功能模块的重复开发,MobileProject对于项目的搭建也进行很明...

匿名
2016/08/17
353
0
Android监听输入法弹窗的实现

用过ios的都知道ios上输入法关闭的同时会自动关闭输入框,那么在android上如何实现监听输入法弹出和关闭呢?本篇文章就为你提供了一种可靠的实现方式。 演示效果视频地址 首先在AndroidMani...

海阔天空玩世不恭
2016/11/15
401
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

前端基础

1. get请求传参长度的误区 误区:我们经常说get请求参数的大小存在限制,而post请求的参数大小是无限制的。 实际上HTTP 协议从未规定 GET/POST 的请求长度限制是多少。对get请求参数的限制是...

wenxingjun
今天
0
0
Android 复制和粘贴功能

做了一回搬运工,原文地址:https://blog.csdn.net/kennethyo/article/details/76602765 Android 复制和粘贴功能,需要调用系统服务ClipboardManager来实现。 ClipboardManager mClipboardM...

她叫我小渝
今天
0
0
拦截SQLSERVER的SSL加密通道替换传输过程中的用户名密码实现运维审计(一)

工作准备 •一台SQLSERVER 2005/SQLSERVER 2008服务 •SQLSERVER jdbc驱动程序 •Java开发环境eclipse + jdk1.8 •java反编译工具JD-Core 反编译JDBC分析SQLSERVER客户端与服务器通信原理 SQ...

紅顏為君笑
今天
6
0
jQuery零基础入门——(六)修改DOM结构

《jQuery零基础入门》系列博文是在廖雪峰老师的博文基础上,可能补充了个人的理解和日常遇到的点,用我的理解表述出来,主干出处来自廖雪峰老师的技术分享。 在《零基础入门JavaScript》的时...

JandenMa
今天
0
0
linux mint 1.9 qq 安装

转: https://www.jianshu.com/p/cdc3d03c144d 1. 下载 qq 轻聊版,可在百度搜索后下载 QQ7.9Light.exe 2. 去wine的官网(https://wiki.winehq.org/Ubuntu) 安装 wine . 提醒网页可以切换成中...

Canaan_
今天
0
0
PHP后台运行命令并管理运行程序

php后台运行命令并管理后台运行程序 class ProcessModel{ private $pid; private $command; private $resultToFile = ''; public function __construct($cl=false){......

colin_86
今天
1
0
数据结构与算法4

在此程序中,HighArray类中的find()方法用数据项的值作为参数传递,它的返回值决定是否找到此数据项。 insert()方法向数组下一个空位置放置一个新的数据项。一个名为nElems的字段跟踪记录着...

沉迷于编程的小菜菜
今天
1
1
fiddler安装和基本使用以及代理设置

项目需求 由于开发过程中客户端和服务器数据交互非常频繁,有时候服务端需要知道客户端调用接口传了哪些参数过来,这个时候就需要一个工具可以监听这些接口请求参数,已经接口的响应的数据,这种...

银装素裹
今天
0
0
Python分析《我不是药神》豆瓣评论

读取 Mongo 中的短评数据,进行中文分词 对分词结果取 Top50 生成词云 生成词云效果 看来网上关于 我不是药神 vs 达拉斯 的争论很热啊。关于词频统计就这些,代码中也会完成一些其它的分析任...

猫咪编程
今天
0
0
虚拟机怎么安装vmware tools

https://blog.csdn.net/tjcwt2011/article/details/72638977

AndyZhouX
昨天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部