博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
友盟自定义页面分享功能实现
阅读量:6904 次
发布时间:2019-06-27

本文共 6537 字,大约阅读时间需要 21 分钟。

  hot3.png

贡献作者 -【XJDomain】

博客XJ: 
GitHub直播地址

 

211232_7Frk_2684046.gif

 

 

 

 

1:学习链接:

 

http://dev.umeng.com/social/ios/detail-share

YLShareView.h

////  YLShareView.h//  YangLand////  Created by 李胜兵 on 14/3/25.//  Copyright © 2014年 tshiny. All rights reserved.//#import "BaseView.h"#import "YLShareContentSourceView.h"@interface YLShareView : BaseView@property (strong, nonatomic)YLShareContentSourceView *bottomView;/** *  显示 */- (void)show;/** *  消失 */- (void)dismiss;@end

 

////  YLShareView.m//  YangLand////  Created by 李胜兵 on 14/3/25.//  Copyright © 2014年 tshiny. All rights reserved.//#import "YLShareView.h"static CGFloat bottomViewHeight = 200;  // bottomView高度@interface YLShareView ()
@end@implementation YLShareView- (instancetype)initWithFrame:(CGRect)frame {    if (self = [super initWithFrame:frame]) {        self.backgroundColor = [UIColor colorWithWhite:.3 alpha:.3];         [self addSubview:self.bottomView];    }    return self;}- (void)setUpUI {    [self addSubview:self.bottomView];}- (void)show {    UIWindow *window = [[UIApplication sharedApplication].windows lastObject];    // 模版的大小等于窗口的大小    self.frame = window.bounds;    [window addSubview:self];    [YLAnimaitonTool showAnimationFlashWithView:self.bottomView duration:.5];     self.bottomView.alpha = 1;}- (void)dismiss {        [UIView animateWithDuration:.7 animations:^{        self.bottomView.alpha = 0;    } completion:^(BOOL finished) {               [self removeFromSuperview];            }];}- (void)touchesBegan:(NSSet
 *)touches withEvent:(UIEvent *)event {    [self dismiss];}#pragma mark - YLShareContentSourceViewDelegate代理 、- (void)tapCancelButtom {    [self dismiss];}#pragma mark - get- (YLShareContentSourceView *)bottomView {    if (!_bottomView) {        NSArray *array = @[@"新浪",@"微信",@"朋友圈",@"QQ"]; //分享来源个数        bottomViewHeight = bottomViewHeight<200?200:bottomViewHeight;// 限制他人设置低于200的高度       _bottomView = [[YLShareContentSourceView alloc]initWithFrame:CGRectMake(0, YLScreenH-bottomViewHeight, YLScreenW, bottomViewHeight) withShareSourceArray:array];        _bottomView.delegate  = self;    }    return _bottomView;}@end

 

////  YLShareContentSourceView.h//  YangLand////  Created by 李胜兵 on 14/3/28.//  Copyright © 2014年 tshiny. All rights reserved.//#import "BaseView.h"@class YLShareContentSourceView;@protocol YLShareContentSourceViewDelegate 
/** *  点击取消按钮,触发事件 */- (void)tapCancelButtom;- (void)shareWithSNSType:(NSString *)type;@end@interface YLShareContentSourceView : BaseView@property (weak, nonatomic)id
delegate;- (instancetype)initWithFrame:(CGRect)frame withShareSourceArray:(NSArray *)array;@end

 

////  YLShareContentSourceView.m//  YangLand////  Created by 李胜兵 on 14/3/28.//  Copyright © 2014年 tshiny. All rights reserved.//#import "YLShareContentSourceView.h"#import "shareTool.h"static CGFloat normalHeight = 50;          //  默认上下高度static CGFloat verticalSpace = 10;        //  上下间距static CGFloat imageHeight = 50;         //  图片高度=宽度static NSInteger showCount = 4;         //  一行显示分享来源个数@interface YLShareContentSourceView ()@property (strong, nonatomic)UILabel *shareWhereLabel; // 分享去哪儿@property (strong, nonatomic)UIButton *cancelBtn; // 取消按钮@property (strong, nonatomic)UIScrollView *scrollView;@end@implementation YLShareContentSourceView- (instancetype)initWithFrame:(CGRect)frame withShareSourceArray:(NSArray *)array {    self = [super initWithFrame:frame];    if (self) {        self.backgroundColor = [UIColor whiteColor];                [self addSubview:self.shareWhereLabel];        [self addSubview:self.cancelBtn];        [self addSubview:self.scrollView];                UIScrollView *scrollView= [[UIScrollView alloc]initWithFrame:CGRectMake(0, normalHeight+verticalSpace, YLScreenW, self.height-normalHeight*2-verticalSpace*2)];                NSInteger newCount = 0;        if (array.count%showCount!=0) {            newCount = 1;        }        scrollView.contentSize = CGSizeMake(YLScreenW*(array.count/showCount+newCount), self.height-normalHeight*2-verticalSpace*2);        [self addSubview:scrollView];                        for (int i=0; i

 

      

         

    使用范例:

  1. 在使用控制器中定义属性:

    (strong, nonatomic)YLShareView *shareView;

  2. 初始化:

    #pragma mark - get
    - (YLShareView *)shareView {
        if (!_shareView) {
            _shareView = [YLShareView newAutoLayoutView];
            _shareView.bottomView.delegate = self;
        }
        return _shareView;
    }
     

  3. 在点击按钮中实现调用这个方法:

    - (void)textShareCustomView {

        // 显示
        [self.shareView show];
    }

  4. 实现YLShareContentSourceViewDelegate这个页面的两个代理方法

    1.#pragma mark - 两个代理.....

    - (void)tapCancelButtom {
        [self.shareView dismiss];
    }

    2.- (void)shareWithSNSType:(NSString *)type {

        //即将跳转就让他消失页面
        [self tapCancelButtom];

     [self shareWithPostSNSWithTypes:type content:@"分享内容" image:gifData location:nil urlResource:nil presentedController:self completion:^(UMSocialResponseEntity *response) {

            if (response.responseCode == UMSResponseCodeSuccess) {
                YLLog(@"分享成功");
            }
        }];

}

 

上面一个方法的解释:

这个方法可以写在基类控制器中如:BaseViewController,每个控制器继承自这个控制器的时候,可以直接调用即可

/** *  分享 * *  @param shareType  分享类型 *  @param Content    分享内容 *  @param image      分享图片 *  @param location   分享位置 *  @param urlResouce 分享资源路径 *  @param vc         当前分享的控制器管理 *  @param Completion 完成后的回调 */- (void)shareWithPostSNSWithTypes:(NSString *)shareType content:(NSString *)Content image:(id)image location:(CLLocation *)location urlResource:(UMSocialUrlResource *)urlResouce presentedController:(UIViewController *)vc completion:(void(^)(UMSocialResponseEntity *response))Completion;

 

 

 

 

/** *  分享方法 */- (void)shareWithPostSNSWithTypes:(NSString *)shareType content:(NSString *)Content image:(id)image location:(CLLocation *)location urlResource:(UMSocialUrlResource *)urlResouce presentedController:(UIViewController *)vc completion:(void (^)(UMSocialResponseEntity *))Completion {    if ([shareType isEqualToString:UMShareToSina]) {                  // 新浪            }else if ([shareType isEqualToString:UMShareToWechatSession]) {   // 微信好友            }else if ([shareType isEqualToString:UMShareToWechatTimeline]) {  // 微信朋友圈            }else if ([shareType isEqualToString:UMShareToQQ]) {              // QQ            }            [[UMSocialDataService defaultDataService]  postSNSWithTypes:@[shareType] content:Content image:image location:location urlResource:urlResouce presentedController:vc completion:^(UMSocialResponseEntity *response){        if (Completion) {            Completion (response);        }    }];        }

 

YLShareView.m文件中使用一个动画是我的flash动画博客中那个方法,直接调用即可,可以写在一个工具类中即可!

 

 

后期如果有什么问题可以在评论下留下你的联系方便为你解答,谢谢!

 

 

 

 

 

 

 

 

 

        

                                                                         

 

 

 

    

 

 

 

                    

转载于:https://my.oschina.net/shengbingli/blog/649501

你可能感兴趣的文章
JNI学习笔记(三)JNI中本地语言访问Java类中的属性与方法(附例子)
查看>>
推荐一篇信息系统项目管理师备考的方案(作者:马甲三号) ...
查看>>
ufw ubuntu防火墙
查看>>
【转载】Oracle ASM
查看>>
《机器学习实战》中Logistic回归几个算法的解析
查看>>
设置交互要多久?最快只需三秒!
查看>>
我的友情链接
查看>>
页面loading效果
查看>>
关于SUID、SGID、SBIT
查看>>
高性能计算机的发展趋势
查看>>
理解ICMPv6前缀请求与前缀公告消息
查看>>
Bootstrap4从入门到精通
查看>>
安卓githup项目归纳
查看>>
Item 46: Use Built-in Algorithms and Data Structures
查看>>
UIkit框架(14)自定义标签控制器
查看>>
文件的读写
查看>>
夭折的TMG,微软停止开发TMG 相关产品
查看>>
坑- observeOn(AndroidSchedulers.mainThread())
查看>>
我的友情链接
查看>>
Vert.x 单元测试 译<六>
查看>>