用到的一些工具

#import <Foundation/Foundation.h>

#import <UIKit/UIKit.h>


@interface Team9Tool : NSObject

#pragma mark 标准label

+ (CGFloat)heightByFloatSize:(CGFloat)fontSize

                        With:(NSString *)text;

#pragma mark 任意label

+ (CGFloat)heightByFloatSize:(CGFloat)fontSize

                       width:(CGFloat)width

                        With:(NSString *)text;

#pragma mark sd_image

+ (void)sd_imageView:(UIImageView *)imageView

               image:(NSString *)str

    placeholderImage:(NSString *)placeholder;

#pragma mark sd_imageView 完成之后的方法 封装 1.image 2 image name

+ (void)sd_imageView:(UIImageView *)imageView

               image:(NSString *)str

         placeholder:(UIImage *)placeholderImage;

+ (void)sd_imageView:(UIImageView *)imageView

               image:(NSString *)str

    placeholderImage:(NSString *)placeholder

         detailImage:(NSString *)detailStr;


#pragma mark sd_imageView 进度条的封装

+ (void)sd_progress_imageView:(UIImageView *)imageView

               image:(NSString *)str

             placeholderImage:(NSString *)placeholder;


#pragma mark sd_imageView push 到各种页面的封装

// 点击push tabar

+ (void)imageView:(UIImageView *)imageView

             type:(NSString *)type

               Id:(NSString *)Id

   viewController:(UIViewController *)VC;

// 点击push tabar 可选

+ (void)imageView:(UIImageView *)imageView

             type:(NSString *)type

               Id:(NSString *)Id

   viewController:(UIViewController *)VC

         baiHiden:(BOOL)hiden;

// 直接push tabar

+ (void)viewContrller:(UIViewController *)VC

           pushBytype:(NSString *)type

                andId:(NSString *)Id;

// 直接push tabar可选

+ (void)viewContrller:(UIViewController *)VC

           pushBytype:(NSString *)type

                andId:(NSString *)Id

             barHiden:(BOOL)hiden;

// 直接push 申请type push tabar

+ (void)imageView:(UIImageView *)imageView

               Id:(NSString *)Id

   viewController:(UIViewController *)VC

         barHiden:(BOOL)hiden;

@end



#import "Team9Tool.h"

#import "Team9Header.h"

#import <UIImageView+WebCache.h>

#import <objc/runtime.h>


#import "Team9ExpertUsersVc.h"

#import "Team9workVc.h"

#import "Team9DesignerVc.h"

#import "JQAFNetworkTool.h"

#import "ConvertToCommonEmoticonsHelper.h"

#import <MBProgressHUD.h>

#import <Masonry.h>


@implementation Team9Tool

#pragma height for text

+ (CGFloat)heightByFloatSize:(CGFloat)fontSize

                        With:(NSString *)text

{

    return [self heightByFloatSize:fontSize width:WIDTH - 20 With:text];;

}

+ (CGFloat)heightByFloatSize:(CGFloat)fontSize

                       width:(CGFloat)width

                        With:(NSString *)text

{

    NSDictionary *fontDic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:fontSize], NSFontAttributeName, nil];

    // 去掉表情的三方

    NSString *string = [ConvertToCommonEmoticonsHelper convertToCommonEmoticons:text];

//    NSLog(@"%@", string);

    CGRect rect = [string boundingRectWithSize:CGSizeMake(width, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDic context:nil];

    

    return rect.size.height;

}

// 没有占位图 直接给333 有不变 调用自己的详细方法

+ (void)sd_imageView:(UIImageView *)imageView

               image:(NSString *)str

    placeholderImage:(NSString *)placeholder

{

    UIImage *placeholderImage = nil;

    if (placeholder) {

        placeholderImage = [UIImage imageNamed:placeholder];

    } else placeholderImage = [UIImage imageNamed:@"333"];

    [self sd_imageView:imageView image:str placeholder:placeholderImage];

}

// 详细的sd完成之后 出现动画

+ (void)sd_imageView:(UIImageView *)imageView

               image:(NSString *)str

         placeholder:(UIImage *)placeholder{

    

    [imageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:placeholder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

        if (cacheType == SDImageCacheTypeDisk) {

            [UIView animateWithDuration:0.3 animations:^{

                CATransition *transition = [CATransition animation];

                transition.type = @"fade";

                [transition setDuration:0.5];

                [transition setRepeatCount:1];

                // imageView上添加动画效果

                [imageView.layer addAnimation:transition forKey:@"transition"];

            }];

        }

    }];

}

/* 关联对象 runtime 把一个progressView 达到一个imageView的效果

    然后把他添加到imageView

    调用方法的时候先移除之前的 进度条 创建个新的

    进度条的方法要gcd返回主线程

    :sd imageView 的方法看不懂请先上github下载demo

 */

static void *progressImageView = "progressImageViewKey";

+ (UIProgressView *)progressImageView:(UIImageView *)imageView{

    UIProgressView *progress = [[UIProgressView alloc] init];

    [imageView addSubview:progress];

    objc_setAssociatedObject(imageView, progressImageView, progress, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

    [progress setTintColor:[UIColor lightGrayColor]];

    [progress mas_makeConstraints:^(MASConstraintMaker *make) {

        make.center.mas_equalTo(imageView);

        make.left.mas_equalTo(imageView).offset(20);

        make.height.equalTo(@20);

    }];

    return progress;

}

+ (void)sd_progress_imageView:(UIImageView *)imageView

                        image:(NSString *)str

             placeholderImage:(NSString *)placeholder{

    UIProgressView *progress = objc_getAssociatedObject(imageView, progressImageView);

    if (progress) {

        [progress removeFromSuperview];

        objc_setAssociatedObject(imageView, progressImageView, nil, OBJC_ASSOCIATION_RETAIN);

    }

    progress = [Team9Tool progressImageView:imageView];

    [imageView sd_setImageWithURL:[NSURL URLWithString:str] placeholderImage:[UIImage imageNamed:placeholder] options: SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {

        dispatch_async(dispatch_get_main_queue(), ^{

           [progress setProgress:(double)receivedSize / expectedSize animated:YES];

        });

        

        

    } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

        [progress removeFromSuperview];

    }];

}

// str 属性 没用写错了,调用了一个sdimageView的方法,看不懂去看demo

+ (void)sd_imageView:(UIImageView *)imageView

               image:(NSString *)str

    placeholderImage:(NSString *)placeholder

         detailImage:(NSString *)detailStr

{

        [imageView sd_setImageWithURL:[NSURL URLWithString:detailStr] placeholderImage:[UIImage imageNamed:placeholder] options:SDWebImageLowPriority | SDWebImageRetryFailed | SDWebImageProgressiveDownload];

}

// 关联对象 添加手势,实现跳转

/*

 参数多的方法 调用参数少的方法

 */

#pragma mark methods

static void *imageViewKey = "imageViewTapKey";


+ (void)imageView:(UIImageView *)imageView

             type:(NSString *)type

               Id:(NSString *)Id

   viewController:(UIViewController *)VC

         baiHiden:(BOOL)hiden

{

    imageView.userInteractionEnabled = YES;

    __weak __typeof(VC)weakVC = VC;

    void(^block)() = ^{

        [self viewContrller:weakVC pushBytype:type andId:Id barHiden:hiden];

    };

    objc_setAssociatedObject(imageView, imageViewKey, block, OBJC_ASSOCIATION_COPY);

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];

    [imageView addGestureRecognizer:tap];

}

+ (void)tapAction:(UIGestureRecognizer *)tap{

   void(^block)() = objc_getAssociatedObject(tap.view, imageViewKey);

    block();

    NSLog(@"test by me");

}

+ (void)imageView:(UIImageView *)imageView

             type:(NSString *)type

               Id:(NSString *)Id

   viewController:(UIViewController *)VC {

  [self imageView:imageView type:type Id:Id viewController:VC baiHiden:NO];

}

+ (void)viewContrller:(UIViewController *)VC

           pushBytype:(NSString *)type

                andId:(NSString *)Id

            barHiden:(BOOL)hiden{

    NSString *url = [NSString stringWithFormat:@"http://api.meilijia.com/app/user_home_page?user_id=%@", Id];

    Team9ExpertUsersVc *vc = [Team9ExpertUsersVc new];

    vc.url = url;

    vc.Id = Id;

    Team9workVc *workVc = [Team9workVc new];

    workVc.url = url;

    workVc.Id =Id;

    Team9DesignerVc *designerVc = [Team9DesignerVc new];

    designerVc.url = url;

    designerVc.Id = Id;

    switch (type.intValue) {

        case 0:

            VC.hidesBottomBarWhenPushed = YES;

            [VC.navigationController pushViewController:vc animated:YES];

            if (hiden) {

                VC.hidesBottomBarWhenPushed = NO;

            }

            break;

        case 1:

            VC.hidesBottomBarWhenPushed = YES;

            [VC.navigationController pushViewController:designerVc animated:YES];

            if (hiden) {

                VC.hidesBottomBarWhenPushed = NO;

            }

            break;

        case 2:

            VC.hidesBottomBarWhenPushed = YES;

            [VC.navigationController pushViewController:workVc animated:YES];

            if (hiden) {

                VC.hidesBottomBarWhenPushed = NO;

            }

            break;

        default:

            break;

    }

}


+ (void)viewContrller:(UIViewController *)VC

           pushBytype:(NSString *)type

                andId:(NSString *)Id{

    [self viewContrller:VC pushBytype:type andId:Id barHiden:NO];

}

static void *imageViewKeyNet = "imageViewTapKeyNet";

+ (void)imageView:(UIImageView *)imageView

               Id:(NSString *)Id

   viewController:(UIViewController *)VC

         barHiden:(BOOL)hiden{

    imageView.userInteractionEnabled = YES;

    __weak __typeof(VC)weakVC = VC;

    void(^block)() = ^{

        NSString *url = [NSString stringWithFormat:@"http://api.meilijia.com/app/user_home_page?user_id=%@", Id];

        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];

        hud.labelText = @"正在查询类型,请等待";

        [hud show:YES];

        [JQAFNetworkTool getUrl:url success:^(id result) {

            NSString *type = result[@"data"][@"user_home_info"][@"user_info"][@"user_type"];

            NSLog(@"%@", type);

            [self viewContrller:weakVC pushBytype:type andId:Id barHiden:hiden];

            [hud hide:YES];

        }];

    };

    objc_setAssociatedObject(imageView, imageViewKeyNet, block, OBJC_ASSOCIATION_COPY);

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapNetAction:)];

    [imageView addGestureRecognizer:tap];

}

+ (void)tapNetAction:(UIGestureRecognizer *)tap{

    void(^block)() = objc_getAssociatedObject(tap.view, imageViewKeyNet);

    block();

    NSLog(@"test by you");

}





@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值