• WKwebview使用


    #import "CJInformationViewController.h"

    #import <WebKit/WebKit.h>

    #import <JavaScriptCore/JavaScriptCore.h>

    #import "CJwebotherCell.h"

    #import "CJCommentCell.h"

    #import "CJRequestManager.h"

    #import "CJDataMode.h"

    #import "CJDatailMode.h"

    #import "CJShoppingCommentModel.h"

    #import "CJbtnview.h"

    #import "CJLoginViewController.h"

    #import "CJThirdPlatformManager.h"

    #import "CJVideoListViewController.h"

    #import "CJOrderViewController.h"

    #import "WKWebView+CJimgUrlArrayKey.h"

    @interface CJInformationViewController ()<WKNavigationDelegate, UIWebViewDelegate,UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>

    {

        

        UIScrollView *bgView;

    }

    @property (nonatomic, copy)NSString *callbackUrl;

    /*

     * WebView

     */

    @property (strong, nonatomic) WKWebView *webView;

    @property (strong, nonatomic) UIScrollView *mainScrollView;

    @property (strong, nonatomic) UITableView  *webTableview;

    @property (strong, nonatomic) NSMutableArray *arrayDS;

    @property (nonatomic,strong)UIView *bottomview;

    @property (nonatomic,strong)CJbtnview *fenxiangbtn;

    @property (nonatomic,strong)CJbtnview *shoucangbtn;

    @property (nonatomic,strong)CJbtnview *dianzanbtn;

    @property (nonatomic,strong)UIView *commentView;//评论View

    @property (nonatomic,strong)UITextField *PLtextField;

    @property (nonatomic,strong)UIButton *commentbutton;//发表评论

    @property (assign,nonatomic)BOOL dianzan;

    @property (assign,nonatomic)BOOL shoucang;

    @property (nonatomic,strong)NSString * hdpath;

    @property (nonatomic,strong)NSMutableArray *videoLeftArr; //剩余相关视频

    @property (nonatomic,strong)NSMutableArray *allUrlArray;

    @end

    @implementation CJInformationViewController

    -(void)viewWillAppear:(BOOL)animated

    {

        [super viewWillDisappear:animated];

        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;

        

        if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {

            self.edgesForExtendedLayout = UIRectEdgeNone;

        }

    }

    -(WKWebView *)webView{

        if (!_webView) {

            _webView = [[WKWebView alloc] initWithFrame:CGRectMake(0.f, 0.f, self.view.width, 0)];

            _webView.navigationDelegate = self;

            _webView.scrollView.scrollEnabled = NO;

          

        }

        return _webView;

    }

    -(UITableView *)webTableview{

        

        if (!_webTableview) {

            //创建tableview

            _webTableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];

            _webTableview.backgroundColor = [UIColor clearColor];

            _webTableview.delegate = self;

            _webTableview.dataSource = self;

            //禁止滑动

            _webTableview.scrollEnabled = NO;

           

           

        }

        return _webTableview;

    }

    -(void)viewWillDisappear:(BOOL)animated{

        [super viewWillDisappear:animated];

        

        [QBProgressHUDView dismissHUDView];

        

    }

    - (void)viewDidLoad {

        [super viewDidLoad];

        

        _arrayDS = [[NSMutableArray alloc]init];

        _videoLeftArr = [[NSMutableArray alloc]init];

       

        [self setupUI];

       

       

        //请求数据

        [self releData];

      

        [self creatbottom];

        //关闭iqkey

        [[IQKeyboardManager sharedManager] setEnable:NO];

        [[IQKeyboardManager sharedManager] setEnableAutoToolbar:NO];

        //键盘的通知

        

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillUp:) name:UIKeyboardWillShowNotification object:nil];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboradWillDown:) name:UIKeyboardWillHideNotification object:nil];

        

        [self.view addSubview:self.commentView];

        [self.commentView addSubview:self.PLtextField];

        [self.commentView addSubview:self.commentbutton];

    }

    -(void)setupUI{

        

        self.title = @"";

        self.view.backgroundColor = [UIColor whiteColor];

        [QBProgressHUDView showLoadNetworkProgressMessage:@"正在加载..." progressViewStyle:SVProgressHUDStyleLight maskType:SVProgressHUDMaskTypeNone animationStyle:SVProgressHUDAnimationTypeNative];

        

        

        UIScrollView *mainScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.view.height-NAV_BAR_BOTTOM - TOOLBAR_HEIGHT)];

      //  mainScrollView.bounces = NO;

        mainScrollView.delegate = self;

        mainScrollView.showsVerticalScrollIndicator = NO;

        mainScrollView.showsHorizontalScrollIndicator = NO;

        mainScrollView.backgroundColor = [UIColor clearColor];

    //    mainScrollView.contentSize = CGSizeMake(SCREEN_WIDTH, 1000);

        [self.view addSubview:mainScrollView];

        self.mainScrollView = mainScrollView;

        

        //tableview

        [self.mainScrollView addSubview:self.webTableview];

    }

    //webview的数据请求

    -(void)WebviewloadData{

       

        NSURL *url = [NSURL URLWithString:self.hdpath];//self

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        [self.webView loadRequest:request];

        

        [self.webView addObserver:self forKeyPath:@"scrollView.contentSize" options:NSKeyValueObservingOptionNew context:@"WKWebViewContentSize"];

    }

    //请求数据

    -(void)releData{

        

     [QBProgressHUDView showLoadNetworkProgressMessage:@"数据正在加载中!" progressViewStyle:SVProgressHUDStyleLight maskType:SVProgressHUDMaskTypeClear animationStyle:SVProgressHUDAnimationTypeNative];

        CJAppData *user =  [CJAppData instance];

        NSMutableDictionary *headerDic = [NSMutableDictionary dictionary];

        [headerDic setObject:user.userid forKey:@"userid"];

        [headerDic setObject:user.token forKey:@"token"];

        

       

        NSMutableDictionary *bodyDic = [NSMutableDictionary dictionary];

        NSString* vid = self.homemodel.vid;

      

        [bodyDic setObject:vid forKey:@"vid"];

        

        [CJRequestManager postRequestWithUrl:@"/cjv5/vdetail_url" andHeaderDict:headerDic andBodyDict:bodyDic withSuccessBlock:^(NSDictionary *responseObject) {

       

            NSLog(@"%@",responseObject);

            

          

            

            NSDictionary *bodyDict = responseObject[@"body"];

            

            NSArray *about = bodyDict[@"videoinfo"];

         

            if (about != nil) {

                

                NSMutableArray *channels = [CJHomeVideoListModel mj_objectArrayWithKeyValuesArray:about];

                for (int i = 0; i<channels.count; i++) {

                    if (i != 0) {

                        [_videoLeftArr addObject:channels[i]];

                    }

                }

                

                CJHomeVideoListModel *datatailmodel =channels.firstObject;

                _homemodel = datatailmodel;

                self.hdpath= datatailmodel.hdpath;

                

                //是否点赞

                self.dianzan = [datatailmodel.isok isEqualToString:@"0"] ? YES : NO;

                _dianzanbtn.selected = _dianzan;

                

                //是否收藏

                self.shoucang = [datatailmodel.isfav isEqualToString:@"0"] ? YES: NO;

                

                _shoucangbtn.selected = _shoucang;

                

                if (_videoLeftArr.count != 0) {

                    [self.arrayDS addObject:_videoLeftArr];

                }

            }

            

            

            NSArray *about_conment = bodyDict[@"conment"];

            if (about_conment != nil) {

                

                NSArray *channels = [CJShoppingCommentModel mj_objectArrayWithKeyValuesArray:about_conment];

                

                [self.arrayDS addObject:channels];

                

            }

            NSLog(@"rowArray is = %@",_arrayDS);

    //        [self.webTableview reloadData];

            [QBProgressHUDView dismissHUDView];

            

            //web

            [self.mainScrollView addSubview:self.webView];

            //web 赋值

            [self WebviewloadData];

            

            [self.webTableview reloadData];

              [QBProgressHUDView dismissHUDView];

        } andFailureBlock:^(NSURLSessionDataTask *task, NSError *error) {

            

              [QBProgressHUDView dismissHUDView];

            CJLog(@"数据失败 Error = %@", error);

        }];

    }

    #pragma -mark   --------scrollview代理方法---------

    - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{

    }

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView{

      

    }

    //监听

    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{

        if (!self.webView.isLoading) {

            if ([keyPath isEqualToString:@"scrollView.contentSize"]) {

                CGFloat webViewHeight=[self.webView.scrollView contentSize].height;

                CGRect newFrame = self.webView.frame;

                newFrame.size.height = webViewHeight;

                self.webView.frame = newFrame;

                

                CGFloat tableViewH = self.webTableview.contentSize.height;

                self.webTableview.frame = CGRectMake(0.f, self.webView.bottom, self.view.width, tableViewH);

                

                //设置scrollview滚动的大小

                _mainScrollView.contentSize = CGSizeMake(0, webViewHeight + tableViewH);

                CJLog(@"");

            }

        }

    }

    #pragma mark - WKNavigationDelegate

    /**

     *  页面开始加载时调用

     *

     *  @param webView    实现该代理的webview

     *  @param navigation 当前navigation

     */

    - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {

        

        NSLog(@"%s", __FUNCTION__);

    }

    /**

     *  当内容开始返回时调用

     *

     *  @param webView    实现该代理的webview

     *  @param navigation 当前navigation

     */

    - (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {

        

        NSLog(@"%s", __FUNCTION__);

    }

    /**

     *  页面加载完成之后调用

     *

     *  @param webView    实现该代理的webview

     *  @param navigation 当前navigation

     */

    - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {

        //通过js获取htlm中图片url

       // [webView getImageUrlByJS:webView];

        

        NSLog(@"%s", __FUNCTION__);

         [QBProgressHUDView dismissHUDView];

        //给网页中的图片添加点击方法

        [self addImgClickJS];

        

       

    }

    -(void)addImgClickJS{

        //js方法遍历图片添加点击事件 返回图片个数

        /*这块我着重说几句

         逻辑:

         1.遍历获取全部的图片;

         2.生成一个Srting为所有图片的拼接,拼接时拿到所处数组下标;

         3.为图片添加点击事件,并添加数组所处下标

         注意点:

         1.如果仅仅拿到url而无下标的话,网页中如果有多张相同地址的图片 则会发生位置错乱

         2.声明时不要用 var yong let  不然方法添加的i 永远是length的值

         */

        static  NSString * const jsGetImages =

        @"function getImages(){

        var objs = document.getElementsByTagName("img");

        var imgScr = '';

        for(let i=0;i<objs.length;i++){

        imgScr = imgScr + objs[i].src +'LQXindex'+ i +'L+Q+X';

        objs[i].onclick=function(){

        document.location="myweb:imageClick:"+this.src + 'LQXindex' + i;

        };

        };

        return imgScr;

        };";

        [self.webView evaluateJavaScript:jsGetImages completionHandler:^(id _Nullable result, NSError * _Nullable error) {

            

        }];

        //注入自定义的js方法后别忘了调用 否则不会生效(不调用也一样生效了,,,不明白)

        

        [self.webView evaluateJavaScript:@"getImages()" completionHandler:^(id _Nullable result, NSError * _Nullable error) {

            NSString *urlResurlt = result;

            _allUrlArray = [NSMutableArray arrayWithArray:[urlResurlt componentsSeparatedByString:@"L+Q+X"]];

            if (_allUrlArray.count >= 2) {

                [_allUrlArray removeLastObject];// 此时数组为每一个图片的url

            }

        }];

        

    }

    /// 给网页中的图片添加点击方法

    /**

     *  加载失败时调用

     *

     *  @param webView    实现该代理的webview

     *  @param navigation 当前navigation

     *  @param error      错误

     */

    - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error {

        

      

        NSLog(@"%s", __FUNCTION__);

    }

    //// 类似 UIWebView 的 -webView: shouldStartLoadWithRequest: navigationType:

    //- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {

    //

    //    [self.webView showBigImage:navigationAction.request];

    //

    //    decisionHandler(WKNavigationActionPolicyAllow);

    //}

    - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {

        NSString *requestString = [[navigationAction.request URL] absoluteString];

        //hasPrefix 判断创建的字符串内容是否以pic:字符开始

        if ([requestString hasPrefix:@"myweb:imageClick:"]) {

            NSString *imageUrl = [requestString substringFromIndex:@"myweb:imageClick:".length];

            if (bgView) {

                //设置不隐藏,还原放大缩小,显示图片

                bgView.hidden = NO;

                NSArray *imageIndex = [NSMutableArray arrayWithArray:[imageUrl componentsSeparatedByString:@"LQXindex"]];

                int i = [imageIndex.lastObject intValue];

                [bgView setContentOffset:CGPointMake(SCREEN_WIDTH *i, 0)];

            }else{

                [self showBigImage:imageUrl];//创建视图并显示图片

            }

            

        }

        

        

        decisionHandler(WKNavigationActionPolicyAllow);

        

    }

    #pragma mark 显示大图片

    -(void)showBigImage:(NSString *)imageUrl{

        //创建灰色透明背景,使其背后内容不可操作

        bgView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];

        [bgView setBackgroundColor:[UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:0.7]];

        bgView.contentSize = CGSizeMake(SCREEN_WIDTH *_allUrlArray.count, SCREEN_HEIGHT);

        bgView.pagingEnabled = YES;

        [self.view addSubview:bgView];

        

        //创建关闭按钮

        UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];

        closeBtn.backgroundColor = [UIColor redColor];

        [closeBtn addTarget:self action:@selector(removeBigImage) forControlEvents:UIControlEventTouchUpInside];

        [closeBtn setFrame:CGRectMake(SCREEN_WIDTH/2.0 - 13, 200, 26, 26)];

        [self.view addSubview:closeBtn];

        

        //创建显示图像视图

        for (int i = 0; i < _allUrlArray.count; i++) {

            UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH *i, (SCREEN_HEIGHT - 240)/2.0, SCREEN_WIDTH-20, 240)];

            [bgView addSubview:borderView];

            UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, CGRectGetWidth(borderView.frame)-20, CGRectGetHeight(borderView.frame)-20)];

            imgView.userInteractionEnabled = YES;

            

            NSArray *imageIndex = [NSMutableArray arrayWithArray:[_allUrlArray[i] componentsSeparatedByString:@"LQXindex"]];

            

            [imgView sd_setImageWithURL:[NSURL URLWithString:imageIndex.firstObject] placeholderImage:nil];

            

            [borderView addSubview:imgView];

            

        }

        NSArray *imageIndex = [NSMutableArray arrayWithArray:[imageUrl componentsSeparatedByString:@"LQXindex"]];

        

        

        int i = [imageIndex.lastObject intValue];

        [bgView setContentOffset:CGPointMake(SCREEN_WIDTH *i, 0)];

        

    }

    //关闭按钮

    -(void)removeBigImage

    {

        bgView.hidden = YES;

    }

    #pragma -mark   -------uitableviewdelegate----

    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

    {

        

    //    NSInteger a = self.arrayDS.count ;

        return self.arrayDS.count;

    }

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    {

    //    CJDataMode *mode = [self.arrayDS objectAtIndex:section];

        

    //    if (section == 0 ) {

    //        return [self.arrayDS.firstObject count];

    //    }else{

    //

    //        return [self.arrayDS.lastObject count];

    //    }

        return [self.arrayDS[section] count];

       

        

    }

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    {

    //    CJDataMode *model = _arrayDS[indexPath.section];

        

        if (indexPath.section==0){

            

        CJHomeVideoListModel *videoModel = self.arrayDS.firstObject[indexPath.row];

        static NSString *idfir1=@"cjlike";

        CJwebotherCell *cell=[tableView dequeueReusableCellWithIdentifier:idfir1];

      

        if (cell==nil) {

            

            cell=[[CJwebotherCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:idfir1];

        }

        

        cell.selectionStyle = UITableViewCellSelectionStyleNone;

    //    CJHomeVideoListModel *likemodel = model.rowsArray[indexPath.row];

        cell.model = videoModel;

        return cell;

        }

        

        

        if (indexPath.section == 1) {

            

            CJShoppingCommentModel *commentModel = self.arrayDS.lastObject[indexPath.row];

            static NSString *idfir=@"cjcomment";

            CJCommentCell *cell=[tableView dequeueReusableCellWithIdentifier:idfir];

            

            if (cell==nil) {

                

                cell=[[CJCommentCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:idfir];

            }

            

            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            cell.commentModel = commentModel;

            return cell;

        }

        return nil;

        

    }

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        if (indexPath.section == 0) {

            return 90;

        }

        return 90;

    }

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    {

        [tableView deselectRowAtIndexPath:indexPath animated:YES];

        //猜你喜欢播放赋值vid

        if (indexPath.section==0) {

            CJHomeVideoListModel *videoModel = self.arrayDS.firstObject[indexPath.row];

            if ([videoModel.top_id isEqualToString:@"1"]) { // 购物页

                

                CJOrderViewController *videoPlayerVc = [[CJOrderViewController alloc] init];

                videoPlayerVc.videoListModel = videoModel;

                [self.navigationController pushViewController:videoPlayerVc animated:YES];

            }else if([videoModel.top_id isEqualToString:@"2"]){ // web页

                

                CJInformationViewController *webVc = [[CJInformationViewController alloc] init];

                webVc.homemodel = videoModel;

                [self.navigationController pushViewController:webVc animated:YES];

            }else{ // 3 、列表播放

                

                CJVideoListViewController *videoPlayerVc = [[CJVideoListViewController alloc] init];

                videoPlayerVc.videoModel = videoModel;

                [self.navigationController pushViewController:videoPlayerVc animated:YES];

            }

            

           

        }

    }

    //分组的头部

    -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

    {

        if (section==1) {

            return 66;

        }

        return 0.000;

    }

    -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

        

        if (section==1) {

            

            UIView *back = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 77)];

            back.backgroundColor = [UIColor whiteColor];

            UILabel *label = [[UILabel alloc]initWithFrame:back.bounds];

            label.textAlignment = NSTextAlignmentCenter;

            label.text = @"热门评论";

            label.font = [UIFont systemFontOfSize:16];

            label.textColor = [UIColor redColor];

            // label.backgroundColor = [UIColor grayColor];

            [back addSubview:label];

            

            return back;

            

        }

        return nil;

    }

    -(void)dealloc{

        [[NSNotificationCenter defaultCenter] removeObserver:self];

        [self.webView removeObserver:self forKeyPath:@"scrollView.contentSize" context:@"WKWebViewContentSize"];

    }

    -(void)creatbottom{

        _bottomview = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.height - NAV_BAR_BOTTOM - TOOLBAR_HEIGHT, SCREEN_WIDTH, TOOLBAR_HEIGHT)];

        _bottomview.backgroundColor = [UIColor whiteColor];

        [self.view addSubview:self.bottomview];

        UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        btn.frame =CGRectMake(10, 4, 200, 36);

        btn.backgroundColor = QBCOLOR_RGB(230, 230, 230);

        [btn setTitle:@"我来说一说" forState:UIControlStateNormal];

        

        [btn setTitleColor:QBCOLOR_RGB(130, 130, 130) forState:UIControlStateNormal];

        btn.layer.cornerRadius = 18.0;

        btn.layer.borderColor = QBCOLOR_RGB(230, 230, 230).CGColor;

        btn.layer.borderWidth = 1.0;

        [btn addTarget:self action:@selector(btnClcik:) forControlEvents:UIControlEventTouchUpInside];

        [_bottomview addSubview:btn];

        

        _fenxiangbtn = [[CJbtnview alloc]initWithFrame:CGRectMake(btn.right+5, 0, (SCREEN_WIDTH-btn.width-10-5)/3, 44)];

        _fenxiangbtn.backgroundColor = [UIColor clearColor];

        [_fenxiangbtn setTitleColor:[UIColor colorWithRed:130/255.0f green:130/255.0f blue:130/255.0f alpha:1] forState:UIControlStateNormal];

        [_fenxiangbtn setTitle:@"分享" forState:UIControlStateNormal];

        [_fenxiangbtn setImage:[UIImage imageNamed:@"big_share"] forState:UIControlStateNormal];

        _fenxiangbtn.titleLabel.font = [UIFont systemFontOfSize:10];

        [_fenxiangbtn addTarget:self action:@selector(fenxiangclick) forControlEvents:UIControlEventTouchUpInside];

        [_bottomview addSubview:_fenxiangbtn];

        

        

        

        _shoucangbtn = [[CJbtnview alloc]initWithFrame:CGRectMake(_fenxiangbtn.right, 0, (SCREEN_WIDTH-btn.width-10-5)/3, 44)];

        _shoucangbtn.backgroundColor = [UIColor clearColor];

        [_shoucangbtn setTitleColor:[UIColor colorWithRed:130/255.0f green:130/255.0f blue:130/255.0f alpha:1] forState:UIControlStateNormal];

        [_shoucangbtn setTitle:@"收藏" forState:UIControlStateNormal];

        [_shoucangbtn setImage:[UIImage imageNamed:@"big_collect_nor"] forState:UIControlStateNormal];

        [_shoucangbtn setImage:[UIImage imageNamed:@"big_collect_sel"] forState:UIControlStateSelected];

        _shoucangbtn.titleLabel.font = [UIFont systemFontOfSize:10];

        [_shoucangbtn addTarget:self action:@selector(shoucangClcik:) forControlEvents:UIControlEventTouchUpInside];

        [_bottomview addSubview:_shoucangbtn];

        

        _dianzanbtn = [[CJbtnview alloc]initWithFrame:CGRectMake(_shoucangbtn.right, 0, (SCREEN_WIDTH-btn.width-10-5)/3, 44)];

        _dianzanbtn.backgroundColor = [UIColor clearColor];

        [_dianzanbtn setTitleColor:[UIColor colorWithRed:130/255.0f green:130/255.0f blue:130/255.0f alpha:1] forState:UIControlStateNormal];

        [_dianzanbtn setTitle:@"点赞" forState:UIControlStateNormal];

        [_dianzanbtn setImage:[UIImage imageNamed:@"big_heart_nor"] forState:UIControlStateNormal];

        [_dianzanbtn setImage:[UIImage imageNamed:@"big_heart_sel"] forState:UIControlStateSelected];

        _dianzanbtn.titleLabel.font = [UIFont systemFontOfSize:10];

        [_dianzanbtn addTarget:self action:@selector(dianzanClcik:) forControlEvents:UIControlEventTouchUpInside];

        [_bottomview addSubview:_dianzanbtn];

        

       

        

    }

    #pragma -mark   ========点击事件 收藏,点赞,分享===

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

        

            if (btn.selected) {

                btn.adjustsImageWhenHighlighted = NO;

                CJLog(@"您已经点赞了");

                [QBProgressHUDView showSuccessMessage:@"您已经点过赞了" viewStyle:SVProgressHUDStyleLight];

                return;

            }

            CJAppData *user = [CJAppData instance];

            NSMutableDictionary *headerDic = [NSMutableDictionary dictionary];

            [headerDic setObject:user.userid forKey:@"userid"];

            [headerDic setObject:user.token forKey:@"token"];

            

            NSMutableDictionary *daic = [NSMutableDictionary dictionary];

            //获取他的唯一标示

            NSString *uuid = [CJCMUUIDManager readUUID];

            

            //NSString *ac = _dianzan ? @"1" : @"0";

          

                

            [daic setObject:self.homemodel.vid forKey:@"vid"];

            [daic setObject:@"1" forKey:@"ac"];

            [daic setObject:uuid forKey:@"imei"];

           

            

            

            [CJRequestManager postRequestWithUrl:@"/cjv5/v_ok" andHeaderDict:headerDic andBodyDict:daic withSuccessBlock:^(id responseObject) {

                CJLog(@"%@",responseObject);

                if ([[responseObject[@"header"][@"code"]stringValue] isEqualToString:@"1"]) {

                    btn.selected = YES;

                  

                }

                

            } andFailureBlock:^(NSURLSessionDataTask *task, NSError *error) {

                

                

                

            }];

    }

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

        //    btn.selected = !btn.selected;// fengyong fix

        

            CJAppData *user =  [CJAppData instance];

            NSDictionary *headerDic = @{

                                        

                                        @"userid":user.userid,

                                        @"token":user.token

                                        };

            

            NSMutableDictionary *daic = [NSMutableDictionary dictionary];

            

            NSString *ac = _shoucang ? @"1" : @"0";

            

            [daic setObject:self.homemodel.vid forKey:@"vid"];

            [daic setObject:ac forKey:@"ac"];

            

            [CJRequestManager postRequestWithUrl:@"/cjv5/u_fav" andHeaderDict:headerDic andBodyDict:daic withSuccessBlock:^(id responseObject) {

                

                

                if ([responseObject[@"body"][@"res"] isEqualToString:@"ok"]) {

                    btn.selected = !btn.selected;

                }

                

            } andFailureBlock:^(NSURLSessionDataTask *task, NSError *error) {

                

                

            }];

    }

    -(void)fenxiangclick{

        

        CJHomeVideoListModel *model = [[CJHomeVideoListModel alloc]init];

        model = _homemodel;

        

        CJLog(@"点击了分享按钮");

        

        [CJThirdPlatformManager sharedMessageToPlatform:0  withText:model.title  image:model.cover title:@"今日财界-优质生活发现者" shareURL:model.vid responseState:^(CJThirdPlatformResponseState sharedState) {

            

            if (sharedState == CJThirdPlatformStateSuccess) {

                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"

                                                                    message:nil

                                                                   delegate:nil

                                                          cancelButtonTitle:@"确定"

                                                          otherButtonTitles:nil];

                [alertView show];

                

            }else if (sharedState == CJThirdPlatformStateFail){

                

                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"

                                                                message:nil

                                                               delegate:nil

                                                      cancelButtonTitle:@"确定"

                                                      otherButtonTitles:nil, nil];

                [alert show];

            }

        } error:^(NSError *error) {

            CJLog(@"分享失败 Error %@", error);

        }];

        

    }

    #pragma -mark ==============底部View=======

    -(UIView *)commentView{

        if (!_commentView) {

            _commentView = [[UIView alloc]initWithFrame:CGRectMake(0, self.view.bottom-TAB_BAR_HEIGHT, SCREEN_WIDTH, 44)];

            _commentView.backgroundColor = [UIColor colorWithRed:228/255.0f green:228/255.0f blue:228/255.0f alpha:1.0];

            _commentView.hidden = YES;

            _commentView.userInteractionEnabled = YES;

        }

        return _commentView;

    }

    -(UITextField *)PLtextField

    {

        if (!_PLtextField) {

            _PLtextField = [[UITextField alloc]initWithFrame:CGRectMake(10, 7, SCREEN_WIDTH-20-40-10, 30)];

            _PLtextField.backgroundColor = [UIColor whiteColor];

            _PLtextField.placeholder = @"说说你的看法";

            _PLtextField.font = [UIFont systemFontOfSize:12];

            _PLtextField.delegate=self;

            _PLtextField.layer.masksToBounds = YES;

            _PLtextField.layer.cornerRadius = 18.0f;

            _PLtextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 0)];

            _PLtextField.leftViewMode = UITextFieldViewModeAlways;

            

        }

        return _PLtextField;

    }

    -(UIButton *)commentbutton

    {

        if (!_commentbutton) {

            _commentbutton = [[UIButton alloc]initWithFrame:CGRectMake(self.PLtextField.right+10, 7, 40, 30)];

            _commentbutton.backgroundColor = [UIColor colorWithRed:230/255.0f green:0/255.0f blue:19/255.0f alpha:1.0];

            [_commentbutton setTitle:@"发表" forState:UIControlStateNormal];

            //[_commentbutton setTitleEdgeInsets:UIEdgeInsetsMake(0,5, 0, -5)];

            _commentbutton.layer.masksToBounds = YES;

            _commentbutton.layer.cornerRadius = 11.0f;

            _commentbutton.titleLabel.font = [UIFont systemFontOfSize:12];

            

            [_commentbutton addTarget:self action:@selector(FBClick:) forControlEvents:UIControlEventTouchUpInside];

            

        }

        return _commentbutton;

    }

    #pragma -marl  ======发表评论接口=====

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

        

        if (![CJAppData isGuestUser]) {

            NSString *vvid = @"";

            

            

            vvid = _homemodel.vid;

            

            

            CJAppData *user =  [CJAppData instance];

            

            //获取他的唯一标示

            NSString*uuid=[CJCMUUIDManager readUUID];

            

            NSMutableDictionary *headerDic = [NSMutableDictionary dictionary];

            [headerDic setObject:user.userid forKey:@"userid"];

            [headerDic setObject:user.token forKey:@"token"];

            

            NSString *vid = @"";

            

            

            vid = self.homemodel.vid;

            

            

            NSString *checkstr = [NSString stringWithFormat:@"vid++%@uid++%@imei++%@",vid.md5String,user.userid.md5String, uuid.md5String];

            

            NSMutableDictionary *bodyDic = [NSMutableDictionary dictionary];

            [bodyDic setObject:vid forKey:@"vid"];

            [bodyDic setObject:user.nickname forKey:@"uname"];

            [bodyDic setObject:_PLtextField.text  forKey:@"content"];

            [bodyDic setObject:uuid forKey:@"imei"];

            [bodyDic setObject:checkstr.md5String forKey:@"checkstr"];

            

            

            [CJRequestManager postRequestWithUrl:@"/cjv5/v_comment" andHeaderDict:headerDic andBodyDict:bodyDic withSuccessBlock:^(id responseObject) {

                

                

                CJLog(@"%@",responseObject);

                NSDictionary *headDic = responseObject[@"header"];

                NSInteger code = [headDic[@"code"] integerValue];

                if (code == 0) {

                    [QBProgressHUDView showSuccessMessage:@"已提交,待审核..." viewStyle:SVProgressHUDStyleLight];

                    

                    [[NSNotificationCenter defaultCenter] postNotificationName:@"kNotificationWithSendMessageViewClicked" object:@(YES)];

                    [self.webTableview reloadData];

                    [self.view endEditing:YES];

                }

                

            } andFailureBlock:^(NSURLSessionDataTask *task, NSError *error) {

                

                [QBProgressHUDView showErrorMessage:@"发表评论失败,请稍后再试..." viewStyle:SVProgressHUDStyleLight];

                CJLog(@"------ 发表评论失败 Error = %@", error);

                CJLog(@"");

            }];

            

        }else

        {

            CJLoginViewController *login = [[CJLoginViewController alloc]init];

            [self.navigationController pushViewController:login animated:YES];

            

        }

        //清空

        [_PLtextField setText:@""];

        

    }

    #pragma -mar k   --切换底部View-----

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

        

        self.bottomview.hidden = YES;

        self.commentView.hidden = NO;

        

        [_PLtextField becomeFirstResponder];

        

    }

    #pragma mark  ========键盘=========

    - (BOOL)textFieldShouldReturn:(UITextField *)textField{

        

        if (![self.PLtextField isExclusiveTouch]) {

            [self.PLtextField resignFirstResponder];

        }

        return YES;

    }

    - (void)keyboardWillUp:(NSNotification *)notification

    {

       // _backgroundView.hidden = YES;

        self.commentView.hidden = NO;

        self.commentbutton.hidden = NO;

        

        CGRect keyboradFrame  = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];

        CGFloat animationTime = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];

        __weak typeof(self)weakself = self;

        [UIView animateWithDuration:animationTime animations:^{

            CGRect frame      =    weakself.commentView.frame ;

            frame.origin.y  = self.view.height-keyboradFrame.size.height -TOOLBAR_HEIGHT;

            weakself.commentView.frame = frame;

        }];

    }

    - (void)keyboradWillDown:(NSNotification *)notification

    {

     //   _backgroundView.hidden = NO;

        self.commentView.hidden = YES;

        self.bottomview.hidden = NO;

        CGFloat animationTime = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];

        __weak typeof(self)weakself = self;

        [UIView animateWithDuration:animationTime animations:^{

            CGRect frame      = weakself.commentView.frame ;

            frame.origin.y    = self.view.height - TOOLBAR_HEIGHT;

            weakself.commentView.frame = frame;

        }];

    }

    @end

  • 相关阅读:
    高维协方差矩阵估计
    互信息
    投资组合模型
    R语言
    sklearn
    Python学习
    swagger使用过程中遇到的坑
    mysql杂文
    2018狗年,半年报
    Springboot 手动搭建项目 --redis配置&日志完善+用户名
  • 原文地址:https://www.cnblogs.com/whx060900/p/8287430.html
Copyright © 2020-2023  润新知