|
|
@@ -0,0 +1,295 @@
|
|
|
+//
|
|
|
+// ShareViewController.m
|
|
|
+// KeleAppProject
|
|
|
+//
|
|
|
+// Created by 熊竹 on 2018/3/5.
|
|
|
+// Copyright © 2018年 Cen Zhou. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#import "ShareViewController.h"
|
|
|
+#import "HomeModel.h"
|
|
|
+#import "ShareCell.h"
|
|
|
+#import <UMSocialCore/UMSocialCore.h>
|
|
|
+
|
|
|
+static NSString *shareCell = @"shareCell";
|
|
|
+
|
|
|
+@interface ShareViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
|
|
|
+@property(nonatomic, strong) UICollectionView *collectionView;
|
|
|
+@property(nonatomic, strong) UIView *contentView;
|
|
|
+@property(nonatomic, strong) NSMutableArray *dataArray;
|
|
|
+@property(nonatomic, strong) HomeModel *model;
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation ShareViewController
|
|
|
+- (instancetype)initWithModel:(HomeModel *)model {
|
|
|
+ if (self = [super init]) {
|
|
|
+ _model = model;
|
|
|
+ [self addData];
|
|
|
+ self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
|
|
|
+ self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
|
|
|
+ self.view.userInteractionEnabled = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewDidLoad {
|
|
|
+ [super viewDidLoad];
|
|
|
+ UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(fingerTapped:)];
|
|
|
+ singleTap.cancelsTouchesInView = NO;
|
|
|
+ [self.view addGestureRecognizer:singleTap];
|
|
|
+
|
|
|
+ UIView *contentView = [[UIView alloc] init];
|
|
|
+ contentView.backgroundColor = [UIColor clearColor];
|
|
|
+ self.contentView = contentView;
|
|
|
+ [self.view addSubview:contentView];
|
|
|
+ [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.bottom.left.right.equalTo(self.view);
|
|
|
+ make.height.mas_equalTo(200 * HEIGHT);
|
|
|
+ }];
|
|
|
+ contentView.transform = CGAffineTransformMakeTranslation(0, 200);
|
|
|
+
|
|
|
+ UIView *shareItemView = [[UIView alloc] init];
|
|
|
+ shareItemView.backgroundColor = KLColor_C1;
|
|
|
+ [contentView addSubview:shareItemView];
|
|
|
+ shareItemView.layer.masksToBounds = YES;
|
|
|
+ shareItemView.layer.cornerRadius = 10 * WIDTH;
|
|
|
+ [shareItemView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.left.right.equalTo(contentView);
|
|
|
+ make.bottom.equalTo(contentView).offset(-20 * HEIGHT);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [contentView addSubview:self.collectionView];
|
|
|
+
|
|
|
+ UIView *cancelView = [[UIView alloc] init];
|
|
|
+ cancelView.backgroundColor = [UIColor whiteColor];
|
|
|
+ [contentView addSubview:cancelView];
|
|
|
+ UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCancel)];
|
|
|
+ [cancelView addGestureRecognizer:tap];
|
|
|
+ [cancelView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.right.bottom.equalTo(contentView);
|
|
|
+ make.height.mas_equalTo(44 * HEIGHT);
|
|
|
+ }];
|
|
|
+
|
|
|
+ UILabel *cancelTint = [[UILabel alloc] init];
|
|
|
+ cancelTint.text = @"取消";
|
|
|
+ cancelTint.textColor = KLColor_B12;
|
|
|
+ cancelTint.font = [UIFont fontWithName:@"PingFangSC-Regular" size:16 * WIDTH];
|
|
|
+ [cancelView addSubview:cancelTint];
|
|
|
+ [cancelTint mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.center.equalTo(cancelView);
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewWillAppear:(BOOL)animated {
|
|
|
+ [super viewWillAppear:animated];
|
|
|
+ [UIView animateWithDuration:0.2
|
|
|
+ delay:0
|
|
|
+ options:UIViewAnimationOptionCurveEaseInOut
|
|
|
+ animations:^{
|
|
|
+ self.contentView.transform = CGAffineTransformMakeTranslation(0, 0);
|
|
|
+ self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.2];
|
|
|
+ }
|
|
|
+ completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)addData {
|
|
|
+ self.dataArray = [@[@{@"tint": @"微信好友", @"imageName": @"icon_fenxiang_weixin"}, @{@"tint": @"微信朋友圈", @"imageName": @"icon__fenxiang_pengyouquan"}, @{@"tint": @"手机QQ", @"imageName": @"icon_fenxiang_qq"}, @{@"tint": @"QQ空间", @"imageName": @"icon_fenxiang_qqkongjian"}, @{@"tint": @"微博", @"imageName": @"icon_fenxiang_xinlang"}, @{@"tint": @"违规举报", @"imageName": @"icon_fenxiang_jubao"}] mutableCopy];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)fingerTapped:(UITapGestureRecognizer *)gestureRecognizer {
|
|
|
+ CGPoint point = [gestureRecognizer locationInView:self.contentView];
|
|
|
+ if (point.y < 0) {
|
|
|
+ [self tapCancel];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)tapCancel {
|
|
|
+ [UIView animateWithDuration:0.2
|
|
|
+ delay:0
|
|
|
+ options:UIViewAnimationOptionCurveEaseInOut
|
|
|
+ animations:^{
|
|
|
+ self.contentView.transform = CGAffineTransformMakeTranslation(0, 200);
|
|
|
+ self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
|
|
|
+ }
|
|
|
+ completion:^(BOOL finished) {
|
|
|
+ [self dismissViewControllerAnimated:NO completion:nil];
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (UICollectionView *)collectionView {
|
|
|
+ if (!_collectionView) {
|
|
|
+ UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
|
+ // 设置collectionView的滚动方向,需要注意的是如果使用了collectionview的headerview或者footerview的话, 如果设置了水平滚动方向的话,那么就只有宽度起作用了了
|
|
|
+ [layout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
|
|
|
+ [layout setMinimumLineSpacing:30 * HEIGHT];
|
|
|
+ [layout setMinimumInteritemSpacing:0 * WIDTH];
|
|
|
+ [layout setItemSize:CGSizeMake(50 * WIDTH, 80 * HEIGHT)];
|
|
|
+
|
|
|
+ _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 40 * HEIGHT, KLScreenW, 80 * HEIGHT) collectionViewLayout:layout];
|
|
|
+ _collectionView.contentInset = UIEdgeInsetsMake(0, 15 * WIDTH, 0, 15 * WIDTH);
|
|
|
+ _collectionView.backgroundColor = [UIColor clearColor];
|
|
|
+ [_collectionView registerClass:[ShareCell class] forCellWithReuseIdentifier:shareCell];
|
|
|
+ //注册头视图
|
|
|
+ _collectionView.dataSource = self;
|
|
|
+ _collectionView.delegate = self;
|
|
|
+ _collectionView.showsHorizontalScrollIndicator = NO;
|
|
|
+ _collectionView.showsVerticalScrollIndicator = NO;
|
|
|
+ _collectionView.bounces = YES;
|
|
|
+ }
|
|
|
+ return _collectionView;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark -- UICollectionViewDataSource
|
|
|
+
|
|
|
+/** 每组cell的个数*/
|
|
|
+- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|
|
+ return self.dataArray.count;
|
|
|
+}
|
|
|
+
|
|
|
+/** cell的内容*/
|
|
|
+- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+
|
|
|
+ ShareCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:shareCell forIndexPath:indexPath];
|
|
|
+// cell.backgroundColor = [UIColor whiteColor];
|
|
|
+// [cell.titleBtn setTitle:self.dataArray[indexPath.row] forState:UIControlStateNormal];
|
|
|
+ NSDictionary *dic = self.dataArray[indexPath.row];
|
|
|
+ cell.logoImageView.image = [UIImage imageNamed:dic[@"imageName"]];
|
|
|
+ cell.tint.text = dic[@"tint"];
|
|
|
+ return cell;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+#pragma mark -- UICollectionViewDelegate
|
|
|
+
|
|
|
+- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
+ UMSocialPlatformType platform;
|
|
|
+ UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示"
|
|
|
+ message:@"违规举报成功,我们会尽快处理"
|
|
|
+ preferredStyle:UIAlertControllerStyleAlert];
|
|
|
+ UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定"
|
|
|
+ style:UIAlertActionStyleDefault
|
|
|
+ handler:^(UIAlertAction *action) {
|
|
|
+ [self tapCancel];
|
|
|
+ }];
|
|
|
+ [alert addAction:confirm];
|
|
|
+ switch (indexPath.row) {
|
|
|
+ case 0:
|
|
|
+ platform = UMSocialPlatformType_WechatSession;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ platform = UMSocialPlatformType_WechatTimeLine;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ platform = UMSocialPlatformType_QQ;
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ platform = UMSocialPlatformType_Qzone;
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ platform = UMSocialPlatformType_Sina;
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ [self presentViewController:alert animated:YES completion:nil];
|
|
|
+ return;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (indexPath.row == 4) {
|
|
|
+ //创建分享消息对象
|
|
|
+ UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
|
|
|
+
|
|
|
+ //设置文本
|
|
|
+ messageObject.text = [NSString stringWithFormat:@"%@ %@", _model.title, [NSString stringWithFormat:@"http://app.69mx.com/postInfo/share?id=%@", _model.postId]];
|
|
|
+
|
|
|
+ //创建图片内容对象
|
|
|
+ UMShareImageObject *shareObject = [[UMShareImageObject alloc] init];
|
|
|
+ //如果有缩略图,则设置缩略图
|
|
|
+ shareObject.thumbImage = _model.img;
|
|
|
+ [shareObject setShareImage:_model.img];
|
|
|
+
|
|
|
+ //分享消息对象设置分享内容对象
|
|
|
+ messageObject.shareObject = shareObject;
|
|
|
+
|
|
|
+ //调用分享接口
|
|
|
+ [[UMSocialManager defaultManager]
|
|
|
+ shareToPlatform:UMSocialPlatformType_Sina
|
|
|
+ messageObject:messageObject
|
|
|
+ currentViewController:[self findViewController]
|
|
|
+ completion:^(id data, NSError *error) {
|
|
|
+ NSMutableDictionary *params = [@{
|
|
|
+ @"id": _model.postId,
|
|
|
+ @"shareNum": @1,
|
|
|
+ } mutableCopy];
|
|
|
+ [[KeleData sharedInstance]
|
|
|
+ updateNum:params
|
|
|
+ success:^(id responseObject) {
|
|
|
+ }
|
|
|
+ failure:^(NSError *error) {
|
|
|
+ }];
|
|
|
+ }];
|
|
|
+ } else {
|
|
|
+ UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
|
|
|
+ NSString *thumbURL = _model.img;
|
|
|
+ UMShareWebpageObject *shareObject = [UMShareWebpageObject
|
|
|
+ shareObjectWithTitle:@"樱桃视频"
|
|
|
+ descr:_model.title
|
|
|
+ thumImage:thumbURL];
|
|
|
+ shareObject.webpageUrl = [NSString stringWithFormat:@"http://app.69mx.com/postInfo/share?id=%@", _model.postId];
|
|
|
+ messageObject.shareObject = shareObject;
|
|
|
+ [[UMSocialManager defaultManager]
|
|
|
+ shareToPlatform:platform
|
|
|
+ messageObject:messageObject
|
|
|
+ currentViewController:[self findViewController]
|
|
|
+ completion:^(id data, NSError *error) {
|
|
|
+ NSMutableDictionary *params = [@{
|
|
|
+ @"id": _model.postId,
|
|
|
+ @"shareNum": @1,
|
|
|
+ } mutableCopy];
|
|
|
+ [[KeleData sharedInstance]
|
|
|
+ updateNum:params
|
|
|
+ success:^(id responseObject) {
|
|
|
+ }
|
|
|
+ failure:^(NSError *error) {
|
|
|
+ }];
|
|
|
+ }];
|
|
|
+ }
|
|
|
+ [self tapCancel];
|
|
|
+}
|
|
|
+
|
|
|
+- (UIViewController *)findViewController {
|
|
|
+ id target = self;
|
|
|
+ while (target) {
|
|
|
+ target = ((UIResponder *) target).nextResponder;
|
|
|
+ if ([target isKindOfClass:[UIViewController class]]) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UIViewController *vc = target;
|
|
|
+ return vc;
|
|
|
+}
|
|
|
+
|
|
|
+- (NSMutableArray *)dataArray {
|
|
|
+ if (!_dataArray) {
|
|
|
+ _dataArray = [NSMutableArray array];
|
|
|
+ }
|
|
|
+ return _dataArray;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)didReceiveMemoryWarning {
|
|
|
+ [super didReceiveMemoryWarning];
|
|
|
+ // Dispose of any resources that can be recreated.
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+#pragma mark - Navigation
|
|
|
+
|
|
|
+// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
+- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
+ // Get the new view controller using [segue destinationViewController].
|
|
|
+ // Pass the selected object to the new view controller.
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
+@end
|