<熊猫车帮教练>项目总结

自己总结,欢迎指正,不喜勿喷

2017.03.05-2017.05.23

1.融云获取最后一条消息的内容

RCConversation *conversation = [[RCIMClient sharedRCIMClient]getConversation:ConversationType_PRIVATE targetId:[NSString stringWithFormat:@"%lu",(long)model.trainee_id]];
    if ([conversation.senderUserId isEqualToString:[[RCIM sharedRCIM]currentUserInfo].userId]) {
        cell.timeLabel.text = [self timestampConversionDate:conversation.sentTime/1000];
    }else {
        if (conversation.receivedTime != 0) {
            cell.timeLabel.text = [self timestampConversionDate:conversation.receivedTime/1000];
        }else {
            cell.timeLabel.text = @"00:00";
        }
    }
    if (conversation.unreadMessageCount > 0) {
        cell.statusView.hidden = NO;
    }else {
        cell.statusView.hidden = YES;
    }
    if ([conversation.lastestMessage isKindOfClass:[RCTextMessage class]]) {
        cell.contentLabel.text =((RCTextMessage *)conversation.lastestMessage).content;
    }else if ([conversation.lastestMessage isMemberOfClass:[RCVoiceMessage class]]) {
        cell.contentLabel.text = @"[语音]";
    }else if([conversation.lastestMessage isMemberOfClass:[RCLocationMessage class]]) {
        cell.contentLabel.text =((RCLocationMessage *)conversation.lastestMessage).locationName;
    }else if([conversation.lastestMessage isMemberOfClass:[RCImageMessage class]]) {
        cell.contentLabel.text = @"[图片]";
    }else {
        cell.contentLabel.text = @"暂无聊天信息";
    }

2.与Android对接是需带上用户信息

///连接融云
- (void) rongCloudSetting {
    NSString *token = [[NSUserDefaults standardUserDefaults]objectForKey:k_Rong_Token];
    [[RCIM sharedRCIM] connectWithToken:token success:^(NSString *userId) {
        NSLog(@"***登录成功");
        RCUserInfo *userinfo = [[RCUserInfo alloc]initWithUserId:[RCIM sharedRCIM].currentUserInfo.userId name: [[NSUserDefaults standardUserDefaults] objectForKey:k_User_Name] portrait:[[NSUserDefaults standardUserDefaults] objectForKey:k_User_HeadImage]];
        [[RCIM sharedRCIM] setCurrentUserInfo:userinfo];
        [[RCIM sharedRCIM] setEnableMessageAttachUserInfo:YES];
    } error:^(RCConnectErrorCode status) {
        NSLog(@"***登录失败");
    } tokenIncorrect:^{
        NSLog(@"token过期或不正确");
    }];
}

3.提交数据时主window蒙一层防重点

//FactoryClass为自己定义的工厂类
- (void) addFaceViewSetting {
    UIWindow *keywindow = [[UIApplication sharedApplication] keyWindow];
    self.loadBgView = [FactoryClass CreateView:0 Rounded:0 ToView:keywindow];
    self.loadBgView.backgroundColor  = [UIColor colorWithWhite:0 alpha:0.25];
    [self.loadBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(keywindow);
        make.bottom.equalTo(keywindow);
    }];
    self.loadBgView.hidden = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapNoClickEvent)];
    tap.delegate = self;
    [self.loadBgView addGestureRecognizer:tap];
}

4. 比较时间

- (NSInteger) compareStr:(NSString *)timeStr{
    if (timeStr.length < 22) {
        return -2;
    }
    NSString *dayStr = [timeStr substringToIndex:10];
    NSString *hourOneStr = [timeStr substringToIndex:16];
    NSString *hourStr = [timeStr substringFromIndex:timeStr.length - 5];
    NSString *houTwoStr = [NSString stringWithFormat:@"%@ %@",dayStr,hourStr];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
    NSDate *dateA = [dateFormatter dateFromString:hourOneStr];
    NSDate *dateB = [dateFormatter dateFromString:houTwoStr];
    NSDate *dateC = [dateFormatter dateFromString:currentDateStr];
    NSComparisonResult result_1 = [dateC compare:dateA];
    NSComparisonResult result_2 = [dateC compare:dateB];
    //相等
    if (result_1 == NSOrderedAscending) {
        return -1;
    }
    //在某个时间段内
    if ((result_1 == NSOrderedDescending || result_1 == NSOrderedSame)&&(result_2 == NSOrderedAscending || result_2 == NSOrderedSame)) {
        return 0;
    }
    //超过了某个时间
    else if (result_2 == NSOrderedDescending){
        return 1;
    }
    return -2;
}

5.高级控件控制其某类cell是否可以被点击

//开启高级控件的多选
self.collectionView.allowsMultipleSelection = YES;
//是否可以被点击
if (schedule.order == -1) {
                cell.userInteractionEnabled = NO;
                cell.bgView.backgroundColor = [UIColor colorWithRGB:color(FFFFFF)];
            }else if(schedule.order == -2) {
                cell.userInteractionEnabled = YES;
                cell.bgView.backgroundColor = [UIColor colorWithRGB:color(FFB300)];
            }else if(schedule.order == 0) {
                cell.userInteractionEnabled = YES;
                cell.bgView.backgroundColor = [UIColor colorWithRGB:color(65C66E)];
            }else if(schedule.order > 0) {
                cell.userInteractionEnabled = YES;
                cell.bgView.backgroundColor = [UIColor colorWithRGB:[UIColor colorWithMain]];
            }else {
                cell.userInteractionEnabled = NO;
                cell.bgView.backgroundColor = [UIColor colorWithRGB:color(FFFFFF)];
            }
 }

6.创建带有图片的富文本

- (NSAttributedString *) insertImageWithLabel:(NSString *)imageName Text:(NSString *)text {
    // 创建一个富文本
    NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ ",text]];
    [attri addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRGB:[UIColor colorWithMain]]} range:NSMakeRange(0, attri.length)];
    // 添加表情
    NSTextAttachment *attch = [[NSTextAttachment alloc] init];
    // 表情图片
    attch.image = [UIImage imageNamed:imageName];
    // 设置图片大小
    attch.bounds = CGRectMake(0, 0, Size(16), Size(30));
    // 创建带有图片的富文本
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
    [attri insertAttributedString:string atIndex:attri.length];
    //返回
    return attri;
}

7. 时间字符串转某种格式

///NSString转NSDate
- (NSDictionary *) stringConverseDate:(NSString *)dateStr {
    if (dateStr == nil) {
        return nil;
    }
    //需要转换的字符串
    NSString *dateString = dateStr;
    //设置转换格式
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateFormat:@"yyyy-MM-dd"];
    //NSString转NSDate
    NSDate *date=[formatter dateFromString:dateString];
    
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"EEE"];
    NSString *weekStr = [dateFormat stringFromDate:date];
    [dateFormat setDateFormat:@"MM-dd"];
    NSString *dayStr = [dateFormat stringFromDate:date];
    if (weekStr == nil || dayStr == nil) {
        return nil;
    }
    
    //判断当前手机系统的语言选择
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
    NSString *currentLanguage = [languages objectAtIndex:0];
    if ([currentLanguage isEqualToString:@"zh_Hans"]) {
        NSString *weekRstr = [NSString stringWithFormat:@"周%@",[weekStr substringFromIndex:weekStr.length-1]];
        return [[NSDictionary alloc]initWithObjectsAndKeys:weekRstr,@"Week",dayStr,@"MandD", nil];
    }else {
        return [[NSDictionary alloc]initWithObjectsAndKeys:weekStr,@"Week",dayStr,@"MandD", nil];
    }
}

8.移除键盘通知和定时器

- (void)dealloc {
    [self.codeTimer invalidate];
    self.codeTimer = nil;
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}

9.限制输入框的输入长度和限制输入字符

#pragma mark - UITextFieldDeledate 
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    if (textField == self.phoneTextField) {
        if (toBeString.length > 11) {
            return NO;
        }
    }
    if (textField == self.codeTextField) {
        if (toBeString.length > 6) {
            return NO;
        }
    }
    if (textField == self.passwordTextField) {
        if (toBeString.length > 22) {
            return NO;
        }
    }
    if (textField == self.againPasswordTextField) {
        if (toBeString.length > 22) {
            return NO;
        }
    }
    //如果输入的字符串不满足某种格式就不能输入
    if (![YFWLValidationMessage checkUserName:((UITextField *)self.textFieldArray[0]).text]) {
        [YFWLHUDManager showInfoMessage:@"姓名格式错误" duration:1.3];
        return NO;
    }
    return YES;
}

10.正则匹配手机号、身份证、密码和银行卡等格式

#pragma 正则匹配手机号
+ (BOOL)checkTelNumber:(NSString *) telNumber
{
    NSString *pattern = @"^1+[3578]+\\d{9}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:telNumber];
    return isMatch;
}

#pragma 正则匹配用户密码6-22位数字和字母组合
+ (BOOL)checkPassword:(NSString *) password
{
    NSString *pattern = @"^(?![0-9]+$)[a-zA-Z0-9]{6,22}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:password];
    return isMatch;
    
}

#pragma 正则匹配用户姓名,20位的中文或英文
+ (BOOL)checkUserName : (NSString *) userName
{
    NSString *pattern = @"^[a-zA-Z\u4E00-\u9FA5]{1,20}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:userName];
    return isMatch;
}

#pragma 正则匹配用户身份证号15或18位
+ (BOOL)checkUserIdCard: (NSString *) idCard
{
    NSString *pattern = @"(^[0-9]{15}$)|([0-9]{17}([0-9]|X)$)";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:idCard];
    return isMatch;
}

#pragma 正则验证码,6位的数字
+ (BOOL)checkEmployeeNumber : (NSString *) number
{
    NSString *pattern = @"^[0-9]{6}";
    
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:number];
    return isMatch;
}

#pragma 正则匹配URL
+ (BOOL)checkURL : (NSString *) url
{
    NSString *pattern = @"^[0-9A-Za-z]{1,50}";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
    BOOL isMatch = [pred evaluateWithObject:url];
    return isMatch;
}

#pragma 匹配银行卡
+ (BOOL) IsBankCard:(NSString *)cardNumber
{
    if(cardNumber.length==0)
    {
        return NO;
    }
    NSString *digitsOnly = @"";
    char c;
    for (int i = 0; i < cardNumber.length; i++)
    {
        c = [cardNumber characterAtIndex:i];
        if (isdigit(c))
        {
            digitsOnly =[digitsOnly stringByAppendingFormat:@"%c",c];
        }
    }
    int sum = 0;
    int digit = 0;
    int addend = 0;
    BOOL timesTwo = false;
    for (NSInteger i = digitsOnly.length - 1; i >= 0; i--)
    {
        digit = [digitsOnly characterAtIndex:i] - '0';
        if (timesTwo)
        {
            addend = digit * 2;
            if (addend > 9) {
                addend -= 9;
            }
        }
        else {
            addend = digit;
        }
        sum += addend;
        timesTwo = !timesTwo;
    }
    int modulus = sum % 10;
    return modulus == 0;
}

11.判断手机当前类型

//创建方法:给UIDevice建立类别并导入这个头文件#import <sys/utsname.h> 如:@implementation UIDevice (YFWLGetDevice)
//使用方法: [UIDevice deviceModelName];//直接返回当前的手机类型

+ (NSString*)deviceModelName
{
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
    
    //iPhone 系列
    if ([deviceModel isEqualToString:@"iPhone1,1"])    return @"iPhone 1G";
    if ([deviceModel isEqualToString:@"iPhone1,2"])    return @"iPhone 3G";
    if ([deviceModel isEqualToString:@"iPhone2,1"])    return @"iPhone 3GS";
    if ([deviceModel isEqualToString:@"iPhone3,1"])    return @"iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone3,2"])    return @"iPhone 4";
    if ([deviceModel isEqualToString:@"iPhone4,1"])    return @"iPhone 4S";
    if ([deviceModel isEqualToString:@"iPhone5,1"])    return @"iPhone 5";
    if ([deviceModel isEqualToString:@"iPhone5,2"])    return @"iPhone 5";
    if ([deviceModel isEqualToString:@"iPhone5,3"])    return @"iPhone 5C";
    if ([deviceModel isEqualToString:@"iPhone5,4"])    return @"iPhone 5C";
    if ([deviceModel isEqualToString:@"iPhone6,1"])    return @"iPhone 5S";
    if ([deviceModel isEqualToString:@"iPhone6,2"])    return @"iPhone 5S";
    if ([deviceModel isEqualToString:@"iPhone7,1"])    return @"iPhone6 Plus";
    if ([deviceModel isEqualToString:@"iPhone7,2"])    return @"iPhone6";
    if ([deviceModel isEqualToString:@"iPhone8,1"])    return @"iPhone6s";
    if ([deviceModel isEqualToString:@"iPhone8,2"])    return @"iPhone6s Plus";
    if ([deviceModel isEqualToString:@"iPhone9,1"])    return @"iPhone7 (CDMA)";
    if ([deviceModel isEqualToString:@"iPhone9,3"])    return @"iPhone7 (GSM)";
    if ([deviceModel isEqualToString:@"iPhone9,2"])    return @"iPhone7 Plus (CDMA)";
    if ([deviceModel isEqualToString:@"iPhone9,4"])    return @"iPhone7 Plus (GSM)";
    
    //iPod 系列
    if ([deviceModel isEqualToString:@"iPod1,1"])      return @"iPod Touch 1G";
    if ([deviceModel isEqualToString:@"iPod2,1"])      return @"iPod Touch 2G";
    if ([deviceModel isEqualToString:@"iPod3,1"])      return @"iPod Touch 3G";
    if ([deviceModel isEqualToString:@"iPod4,1"])      return @"iPod Touch 4G";
    if ([deviceModel isEqualToString:@"iPod5,1"])      return @"iPod Touch 5G";
    
    //iPad 系列
    if ([deviceModel isEqualToString:@"iPad1,1"])      return @"iPad";
    if ([deviceModel isEqualToString:@"iPad2,1"])      return @"iPad 2 (WiFi)";
    if ([deviceModel isEqualToString:@"iPad2,2"])      return @"iPad 2 (GSM)";
    if ([deviceModel isEqualToString:@"iPad2,3"])      return @"iPad 2 (CDMA)";
    if ([deviceModel isEqualToString:@"iPad2,4"])      return @"iPad 2 (32nm)";
    if ([deviceModel isEqualToString:@"iPad2,5"])      return @"iPad mini (WiFi)";
    if ([deviceModel isEqualToString:@"iPad2,6"])      return @"iPad mini (GSM)";
    if ([deviceModel isEqualToString:@"iPad2,7"])      return @"iPad mini (CDMA)";
    
    if ([deviceModel isEqualToString:@"iPad3,1"])      return @"iPad 3(WiFi)";
    if ([deviceModel isEqualToString:@"iPad3,2"])      return @"iPad 3(CDMA)";
    if ([deviceModel isEqualToString:@"iPad3,3"])      return @"iPad 3(4G)";
    if ([deviceModel isEqualToString:@"iPad3,4"])      return @"iPad 4 (WiFi)";
    if ([deviceModel isEqualToString:@"iPad3,5"])      return @"iPad 4 (4G)";
    if ([deviceModel isEqualToString:@"iPad3,6"])      return @"iPad 4 (CDMA)";
    
    if ([deviceModel isEqualToString:@"iPad4,1"])      return @"iPad Air";
    if ([deviceModel isEqualToString:@"iPad4,2"])      return @"iPad Air";
    if ([deviceModel isEqualToString:@"iPad4,3"])      return @"iPad Air";
    if ([deviceModel isEqualToString:@"iPad5,3"])      return @"iPad Air 2";
    if ([deviceModel isEqualToString:@"iPad5,4"])      return @"iPad Air 2";
    if ([deviceModel isEqualToString:@"i386"])         return @"Simulator";
    if ([deviceModel isEqualToString:@"x86_64"])       return @"Simulator";
    
    if ([deviceModel isEqualToString:@"iPad4,4"]
        ||[deviceModel isEqualToString:@"iPad4,5"]
        ||[deviceModel isEqualToString:@"iPad4,6"])      return @"iPad mini 2";
    
    if ([deviceModel isEqualToString:@"iPad4,7"]
        ||[deviceModel isEqualToString:@"iPad4,8"]
        ||[deviceModel isEqualToString:@"iPad4,9"])      return @"iPad mini 3";
    
    return deviceModel;
}

12.自己解析字符串数组

格式: @"["B1","B2","C1","C2"]"

- (void) loadDataFouncation {
    NSMutableString *strMu = [[NSMutableString alloc]init];
    if (self.isSelectCars) {
        NSString *string = [[NSUserDefaults standardUserDefaults]objectForKey:k_Car_Style];
        strMu = [[NSMutableString alloc]initWithString:string];
    }else {
        NSString *string = [[NSUserDefaults standardUserDefaults]objectForKey:k_License_Style];
        strMu = [[NSMutableString alloc]initWithString:string];
    }
    [strMu replaceOccurrencesOfString:@"[" withString:@"" options:0 range:NSMakeRange(0, strMu.length)];
    [strMu replaceOccurrencesOfString:@"\"" withString:@"" options:0 range:NSMakeRange(0, strMu.length)];
    [strMu replaceOccurrencesOfString:@"]" withString:@"" options:0 range:NSMakeRange(0, strMu.length)];
    NSArray *arrTemp = [strMu componentsSeparatedByString:@","];
    [arrTemp enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [self.dataArray addObject:obj];
    }];
    [self.collectionView reloadData];
}

13.点击缩略图放大图片

创建方法:创建一个NSObject类,将此代码拷贝到.m文件中,.h中申明两个类方法
使用方法:[类名 scanBigImageWithImageArray:图片数组 CurrentIndex:当前下标];

//原始尺寸
static CGRect oldframe;

/**
 *  浏览单张大图
 *
 *  @param currentImageview 图片所在的imageView
 */
+(void)scanBigImageWithImageView:(UIImageView *)currentImageview{
    //当前imageview的图片
    UIImage *image = currentImageview.image;
    //当前视图
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    //背景
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    //当前imageview的原始尺寸->将像素currentImageview.bounds由currentImageview.bounds所在视图转换到目标视图window中,返回在目标视图window中的像素值
    oldframe = [currentImageview convertRect:currentImageview.bounds toView:window];
    [backgroundView setBackgroundColor:[UIColor colorWithRGB:color(000000)]];
    //此时视图不会显示
    [backgroundView setAlpha:0];
    //将所展示的imageView重新绘制在Window中
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:oldframe];
    [imageView setImage:image];
    [imageView setTag:0];
    [backgroundView addSubview:imageView];
    //将原始视图添加到背景视图中
    [window addSubview:backgroundView];
    
    
    //添加点击事件同样是类方法 -> 作用是再次点击回到初始大小
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideImageView:)];
    [backgroundView addGestureRecognizer:tapGestureRecognizer];
    
    //动画放大所展示的ImageView
    
    [UIView animateWithDuration:0.4 animations:^{
        CGFloat y,width,height;
        y = ([UIScreen mainScreen].bounds.size.height - image.size.height * [UIScreen mainScreen].bounds.size.width / image.size.width) * 0.5;
        //宽度为屏幕宽度
        width = [UIScreen mainScreen].bounds.size.width;
        //高度 根据图片宽高比设置
        height = image.size.height * [UIScreen mainScreen].bounds.size.width / image.size.width;
        [imageView setFrame:CGRectMake(0, y, width, height)];
        //重要! 将视图显示出来
        [backgroundView setAlpha:1];
    } completion:^(BOOL finished) {
        
    }];
    
}

/**
 *  浏览数组大图,并带偏移量
 *
 *  @param currentImageArray 图片所在的imageView
 */
+(void)scanBigImageWithImageArray:(NSMutableArray *)currentImageArray CurrentIndex:(NSInteger)currentIndex {
    //当前视图
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    //背景
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    [backgroundView setBackgroundColor:[UIColor colorWithRGB:color(000000)]];
    //此时视图不会显示
    [backgroundView setAlpha:0];
    
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:backgroundView.bounds];
    scrollView.pagingEnabled = YES;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.bounces = NO;
    scrollView.scrollEnabled = YES;
    scrollView.contentSize = CGSizeMake(kMainScreenWidth * currentImageArray.count, kMainScreenHeight);
    [backgroundView addSubview:scrollView];
    
    
    for (NSInteger i = 0; i < currentImageArray.count; i++) {
        NSString *currentURL = currentImageArray[i];
        UIImageView *currentImageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kMainScreenWidth, kMainScreenHeight)];
        [currentImageview sd_setImageWithURL:[NSURL URLWithString:currentURL] placeholderImage:[UIImage imageNamed:@"banner"]];
        currentImageview.contentMode = UIViewContentModeScaleAspectFit;
        currentImageview.origin = CGPointMake(kMainScreenWidth * i, 0);
        currentImageview.centerY = scrollView.centerY;
        [scrollView addSubview:currentImageview];
    }
    
    scrollView.contentOffset = CGPointMake(kMainScreenWidth*currentIndex, 0);
    
    //将原始视图添加到背景视图中
    [window addSubview:backgroundView];
    
    
    //添加点击事件同样是类方法 -> 作用是再次点击回到初始大小
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideImageView:)];
    [backgroundView addGestureRecognizer:tapGestureRecognizer];
    
    //动画放大所展示的ImageView
    [UIView animateWithDuration:0.4 animations:^{
        [backgroundView setAlpha:1];
    } completion:^(BOOL finished) {
        
    }];
    
}

/**
 *  恢复imageView原始尺寸
 *
 *  @param tap 点击事件
 */
+(void)hideImageView:(UITapGestureRecognizer *)tap{
    UIView *backgroundView = tap.view;
    //原始imageview
    UIImageView *imageView = [tap.view viewWithTag:0];
    //恢复
    [UIView animateWithDuration:0.2 animations:^{
        [imageView setFrame:oldframe];
        [backgroundView setAlpha:0];
    } completion:^(BOOL finished) {
        //完成后操作->将背景视图删掉
        [backgroundView removeFromSuperview];
    }];
}

14.给UIColor添加类别

使用实例:
///导航栏的颜色值
+ (UIColor *)colorWithNavigationBar {
    return [UIColor colorWithRGB:color(CB3340)];
}

#pragma 十六进制转RGB值
+ (UIColor *)colorWithRGB:(uint32_t)rgbValue {
    return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0f
                           green:((rgbValue & 0xFF00) >> 8) / 255.0f
                            blue:(rgbValue & 0xFF) / 255.0f
                           alpha:1];
}
#pragma 十六进制转RGBA值
+ (UIColor *)colorWithRGBA:(uint32_t)rgbaValue {
    return [UIColor colorWithRed:((rgbaValue & 0xFF000000) >> 24) / 255.0f
                           green:((rgbaValue & 0xFF0000) >> 16) / 255.0f
                            blue:((rgbaValue & 0xFF00) >> 8) / 255.0f
                           alpha:(rgbaValue & 0xFF) / 255.0f];
}
#pragma 十六进制转RGBA值
+ (UIColor *)colorWithRGB:(uint32_t)rgbValue alpha:(CGFloat)alpha {
    return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0f
                           green:((rgbValue & 0xFF00) >> 8) / 255.0f
                            blue:(rgbValue & 0xFF) / 255.0f
                           alpha:alpha];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,684评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,143评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,214评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,788评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,796评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,665评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,027评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,679评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,346评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,664评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,766评论 1 331
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,412评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,015评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,974评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,073评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,501评论 2 343

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,596评论 18 139
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 171,446评论 25 707
  • 第5章 引用类型(返回首页) 本章内容 使用对象 创建并操作数组 理解基本的JavaScript类型 使用基本类型...
    大学一百阅读 3,211评论 0 4
  • 《说苑》,是一部古代杂史集,由西汉著名的经学家、文学家、目录学家刘向编纂。 《说苑》共20卷,计为:君道、臣术、建...
    金樱子阅读 2,664评论 0 1
  • 说点题外话 本文仅仅适用于新手,我是说很新的手哟,旨在和大家共同了解js的call和apply方法。笔者水平有限,...
    码农小圈圈阅读 582评论 4 4