<熊貓車幫教練>項目總結(jié)

自己總結(jié)兔综,歡迎指正,不喜勿噴

2017.03.05-2017.05.23

1.融云獲取最后一條消息的內(nèi)容

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.提交數(shù)據(jù)時主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;
    }
    //在某個時間段內(nèi)
    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.創(chuàng)建帶有圖片的富文本

- (NSAttributedString *) insertImageWithLabel:(NSString *)imageName Text:(NSString *)text {
    // 創(chuàng)建一個富文本
    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));
    // 創(chuàng)建帶有圖片的富文本
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
    [attri insertAttributedString:string atIndex:attri.length];
    //返回
    return attri;
}

7. 時間字符串轉(zhuǎn)某種格式

///NSString轉(zhuǎn)NSDate
- (NSDictionary *) stringConverseDate:(NSString *)dateStr {
    if (dateStr == nil) {
        return nil;
    }
    //需要轉(zhuǎn)換的字符串
    NSString *dateString = dateStr;
    //設置轉(zhuǎn)換格式
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
    [formatter setDateFormat:@"yyyy-MM-dd"];
    //NSString轉(zhuǎn)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;
    }
    
    //判斷當前手機系統(tǒng)的語言選擇
    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位數(shù)字和字母組合
+ (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位的數(shù)字
+ (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.判斷手機當前類型

//創(chuàng)建方法:給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.自己解析字符串數(shù)組

格式: @"["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.點擊縮略圖放大圖片

創(chuàng)建方法:創(chuàng)建一個NSObject類崎苗,將此代碼拷貝到.m文件中谷徙,.h中申明兩個類方法
使用方法:[類名 scanBigImageWithImageArray:圖片數(shù)組 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所在視圖轉(zhuǎn)換到目標視圖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;
        //高度 根據(jù)圖片寬高比設置
        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) {
        
    }];
    
}

/**
 *  瀏覽數(shù)組大圖,并帶偏移量
 *
 *  @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 十六進制轉(zhuǎn)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 十六進制轉(zhuǎn)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 十六進制轉(zhuǎn)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];
}
最后編輯于
?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末税手,一起剝皮案震驚了整個濱河市蜂筹,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌芦倒,老刑警劉巖艺挪,帶你破解...
    沈念sama閱讀 217,277評論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異兵扬,居然都是意外死亡麻裳,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,689評論 3 393
  • 文/潘曉璐 我一進店門器钟,熙熙樓的掌柜王于貴愁眉苦臉地迎上來津坑,“玉大人,你說我怎么就攤上這事傲霸〗澹” “怎么了?”我有些...
    開封第一講書人閱讀 163,624評論 0 353
  • 文/不壞的土叔 我叫張陵昙啄,是天一觀的道長穆役。 經(jīng)常有香客問我,道長梳凛,這世上最難降的妖魔是什么耿币? 我笑而不...
    開封第一講書人閱讀 58,356評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮韧拒,結(jié)果婚禮上淹接,老公的妹妹穿的比我還像新娘。我一直安慰自己叛溢,他們只是感情好塑悼,可當我...
    茶點故事閱讀 67,402評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著雇初,像睡著了一般拢肆。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,292評論 1 301
  • 那天郭怪,我揣著相機與錄音支示,去河邊找鬼。 笑死鄙才,一個胖子當著我的面吹牛颂鸿,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播攒庵,決...
    沈念sama閱讀 40,135評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼嘴纺,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了浓冒?” 一聲冷哼從身側(cè)響起栽渴,我...
    開封第一講書人閱讀 38,992評論 0 275
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎稳懒,沒想到半個月后闲擦,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,429評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡场梆,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,636評論 3 334
  • 正文 我和宋清朗相戀三年墅冷,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片或油。...
    茶點故事閱讀 39,785評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡寞忿,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出顶岸,到底是詐尸還是另有隱情腔彰,我是刑警寧澤,帶...
    沈念sama閱讀 35,492評論 5 345
  • 正文 年R本政府宣布蜕琴,位于F島的核電站萍桌,受9級特大地震影響宵溅,放射性物質(zhì)發(fā)生泄漏凌简。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,092評論 3 328
  • 文/蒙蒙 一恃逻、第九天 我趴在偏房一處隱蔽的房頂上張望雏搂。 院中可真熱鬧,春花似錦寇损、人聲如沸凸郑。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,723評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽芙沥。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間而昨,已是汗流浹背救氯。 一陣腳步聲響...
    開封第一講書人閱讀 32,858評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留歌憨,地道東北人着憨。 一個月前我還...
    沈念sama閱讀 47,891評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像务嫡,于是被迫代替她去往敵國和親甲抖。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,713評論 2 354

推薦閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理心铃,服務發(fā)現(xiàn)准谚,斷路器,智...
    卡卡羅2017閱讀 134,654評論 18 139
  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,099評論 25 707
  • 第5章 引用類型(返回首頁) 本章內(nèi)容 使用對象 創(chuàng)建并操作數(shù)組 理解基本的JavaScript類型 使用基本類型...
    大學一百閱讀 3,233評論 0 4
  • 《說苑》,是一部古代雜史集厅篓,由西漢著名的經(jīng)學家秀存、文學家、目錄學家劉向編纂羽氮。 《說苑》共20卷或链,計為:君道、臣術档押、建...
    金櫻子閱讀 2,704評論 0 1
  • 說點題外話 本文僅僅適用于新手澳盐,我是說很新的手喲,旨在和大家共同了解js的call和apply方法令宿。筆者水平有限叼耙,...
    碼農(nóng)小圈圈閱讀 590評論 4 4