iOS-小常識知識點(diǎn) (持續(xù)更新)

第一.app如何添加AirDrop文件分享功能

    蘋果在iOS 7 SDK中集成了UIActivityViewController類南用,可以讓你很簡單地就能把AirDrop功能整合進(jìn)app中!
    MobileVLCKit 第三方 多格式支持 視頻播放!

第二.內(nèi)存泄露分析及解決

    靜態(tài)分析內(nèi)存泄露 使用Xcode自帶的Analyze功能(Product-> Analyze)(Shift + Command + B)猪瞬,對代碼進(jìn)行靜態(tài)分析却舀,對于內(nèi)存泄露(Potential Memory Leak), 未使用局部變量(dead store)赌莺,邏輯錯誤(Logic Flaws)以及API使用問題(API-usage)等明確的展示出來。 靜態(tài)分析的內(nèi)存泄露情況比較簡單,開發(fā)者都能很快的解決。這里不做贅述鸠踪。

    動態(tài)分析內(nèi)存泄露 使用Xcode自帶的Profile功能(Product-> Profile)(Command + i)彈出工具框丙者,選擇Leaks打開复斥,選擇運(yùn)行設(shè)備點(diǎn)左上角的Record錄制按鈕,項(xiàng)目就會在已選好的設(shè)備上運(yùn)行械媒,并開始錄制內(nèi)存檢測情況目锭。選Leaks查看泄露情況,在Leaks的詳細(xì)菜單Details選項(xiàng)里選調(diào)用樹Call Tree纷捞,可查看所有內(nèi)存泄露發(fā)生在哪些地方痢虹。再在右側(cè)的齒輪設(shè)置-Call Tree-勾選Hide System Libraries,則可直接看內(nèi)存泄露發(fā)生的函數(shù)名主儡、方法名奖唯。點(diǎn)擊函數(shù)名、方法名糜值,可直接跳到函數(shù)方法的細(xì)節(jié)丰捷,可以看到哪一句代碼出現(xiàn)了內(nèi)存泄露,以及泄露了多少內(nèi)存寂汇。
接下來就要回到Xcode病往,找到出現(xiàn)內(nèi)存泄露的函數(shù)方法,仔細(xì)分析如何出現(xiàn)的內(nèi)存泄露; 一般使用ARC骄瓣,按照上面一提到的內(nèi)存理解和編碼習(xí)慣是不會出現(xiàn)內(nèi)存泄露的停巷。但我們在開發(fā)過程中,經(jīng)常要使用第三方的一些類庫,特別是涉及到加密的類庫畔勤,用c或c++來編碼的加密解密方法蕾各,會出現(xiàn)內(nèi)存泄露。此時庆揪,我們要明白這些內(nèi)存分配示损,需要手動釋放。要一步一步看嚷硫,哪里分配了內(nèi)存检访,在使用完之后一定要記得釋放free它。

調(diào)試內(nèi)存泄露是一件讓人頭疼的事仔掸,如果你不想頭疼脆贵,請保持良好的編碼習(xí)慣。并在開發(fā)到一個階段時起暮,就要及時對應(yīng)用進(jìn)行內(nèi)存泄露分析卖氨。發(fā)現(xiàn)問題,及時修復(fù)负懦。

第三.block循環(huán)利用導(dǎo)致內(nèi)存泄漏

    A *a = [[A alloc] init];
     a.finishBlock = ^(NSDictionary paraments){ [a doSomething]; }; 
    對于這種在block塊里引用對象a的情況筒捺,要在創(chuàng)建對象a時加修飾符block來防止循環(huán)引用。
     block A *a = [[A alloc] init]; 
     a.finishBlock = ^(NSDictionary paraments){ [a doSomething]; }; 
    或 A __block a = [[A alloc] init]; a.finishBlock = ^(NSDictionary paraments){ [a doSomething]; };
     或者纸厉,需要在block中調(diào)用用self的方法系吭、屬性、變量時颗品,可以這樣寫__weak typeof(self) weakSelf = self;在block中使用weakSelf肯尺。
    __weak typeof(self) weakSelf = self; [b doSomethingWithFinishBlock:^{ weakSelf.text = @"內(nèi)存檢測"; [weakSelf doSomething]; }]; 

第四.label 的空格屬性和局部字段顏色

    設(shè)置 label 的 autoresizingMask 為 NO ,可以使用空格間隔字符串!

       [thirdLab setAttributedText:[self changeLabelWithText:@"點(diǎn)擊按鈕去注冊"]];

    //獲取要調(diào)整顏色的文字位置,調(diào)整顏色  ,改變字體大小和字間距
    -(NSMutableAttributedString*)changeLabelWithText:(NSString*)needText  
    {            
        NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:needText];
        
        [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0,1)];
        [attrString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:51/255.0 green:3/255.0 blue:4/255.0 alpha:1] range:NSMakeRange(0,1)];
  
        [attrString addAttribute:NSKernAttributeName value:@1.0f range:NSMakeRange(0, needText.length)];

        [attrString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:16] range:NSMakeRange(1,needText.length-1)];
        [attrString addAttribute:NSForegroundColorAttributeName value:[UIColor blackColor] range:NSMakeRange(1,needText.length-1)];
    
        return attrString;            
    }

第五.過濾字符串

    // 定義一個特殊字符的集合
    NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:
    @"@/:;()¥「」"躯枢、[]{}#%-*+=_\\|~<>$€^?'@#$%^&*()_+'\""];
    // 過濾字符串的特殊字符
    NSString *newString = [trimString stringByTrimmingCharactersInSet:set];    

第六.iOS應(yīng)用直接退出

    - (void)exitApplication {
        AppDelegate *app = [UIApplication sharedApplication].delegate;
        UIWindow *window = app.window;
    
        [UIView animateWithDuration:1.0f animations:^{
            window.alpha = 0;
        } completion:^(BOOL finished) {
            exit(0);
        }];
    }

第七.label 行間距

    -(void)test{
        NSMutableAttributedString *attributedString =    
       [[NSMutableAttributedString alloc] initWithString:self.contentLabel.text];
        NSMutableParagraphStyle *paragraphStyle =  [[NSMutableParagraphStyle alloc] init];  
       [paragraphStyle setLineSpacing:3];
    
        //調(diào)整行間距       
       [attributedString addAttribute:NSParagraphStyleAttributeName 
                             value:paragraphStyle 
                             range:NSMakeRange(0, [self.contentLabel.text length])];
         self.contentLabel.attributedText = attributedString;
    }

第八.設(shè)置滑動的時候隱藏 navigationbar

    第1種:
        navigationController.hidesBarsOnSwipe = Yes
    
    第2種:
        //1.當(dāng)我們的手離開屏幕時候隱藏
    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
    { 
        if(velocity.y > 0) 
        {
        [self.navigationController setNavigationBarHidden:YES animated:YES];
        } else {
        [self.navigationController setNavigationBarHidden:NO animated:YES]; 
        }
    }
    velocity.y這個量则吟,在上滑和下滑時,變化極谐濉(小數(shù))氓仲,但是因?yàn)榉较虿煌姓?fù)之分得糜,這就很好處理  了敬扛。

第九.屏幕截圖

     // 1. 開啟一個與圖片相關(guān)的圖形上下文
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size,NO,0.0);

    // 2. 獲取當(dāng)前圖形上下文
    CGContextRef ctx = UIGraphicsGetCurrentContext();

    // 3. 獲取需要截取的view的layer
    [self.view.layer renderInContext:ctx];

    // 4. 從當(dāng)前上下文中獲取圖片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    // 5. 關(guān)閉圖形上下文
    UIGraphicsEndImageContext();

    // 6. 把圖片保存到相冊
    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

第十.導(dǎo)航欄、狀態(tài)欄和tabbar相關(guān)

1.導(dǎo)航欄

    //隱藏導(dǎo)航欄上的返回字體    
    //Swift
    UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), forBarMetrics: .Default)
    //OC
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

     //自定義導(dǎo)航欄的左右按鈕
        UIButton *searchBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 90, 0, 30, 44)];
        UIBarButtonItem *seaBtn = [[UIBarButtonItem alloc] initWithCustomView:searchBtn];
        self.navigationItem.rightBarButtonItem = seaBtn;

2.狀態(tài)欄

    //所有控制器狀態(tài)欄字體顏色
    狀態(tài)欄字體顏色不同的辦法        
    1)掀亩、在info.plist中舔哪,將View controller-based status bar appearance設(shè)為NO.
    
    2)、在app delegate中:

    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;

    //單獨(dú)某個控制器字體顏色
    3)槽棍、在個別狀態(tài)欄字體顏色不一樣的vc中
    
    -(void)viewWillAppear:(BOOL)animated{
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    }

 3.tabbar

    
    + (void)load
    {
        // 獲取當(dāng)前類的tabBarItem
        UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
        
        // 更改tabbar 選中字體顏色
        UITabBar *tabbar = [UITabBar appearanceWhenContainedIn:self, nil];
        tabbar.tintColor = [UIColor orangeColor];
        
        // 設(shè)置所有item的選中時顏色
        // 設(shè)置選中文字顏色
        // 創(chuàng)建字典去描述文本
        NSMutableDictionary *attSelect = [NSMutableDictionary dictionary];
        // 文本顏色 -> 描述富文本屬性的key -> NSAttributedString.h
        attSelect[NSForegroundColorAttributeName] = [UIColor orangeColor];
        [item setTitleTextAttributes:attSelect forState:UIControlStateSelected];
        
        // 通過normal狀態(tài)設(shè)置字體大小
        // 字體大小 跟 normal
        NSMutableDictionary *attrNormal = [NSMutableDictionary dictionary];
        // 設(shè)置字體
        attrNormal[NSFontAttributeName] = [UIFont systemFontOfSize:13];
        [item setTitleTextAttributes:attrNormal forState:UIControlStateNormal];
        
        // 文字偏移量
        //[item setTitlePositionAdjustment:<#(UIOffset)#>];
        
        // icon偏移量
        // item.imageInsets = UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>);
    }

第十一.去掉 tabbar 和 navgationbar 的黑線

      //去掉tabBar頂部線條
    CGRect rect = CGRectMake(0, 0, 1, 1);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
    CGContextFillRect(context, rect);
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    [self.tabBar setBackgroundImage:img];
    [self.tabBar setShadowImage:img];
    //[self.navigationController.navigationBar setBackgroundImage:img];
    //self.navigationController.navigationBar.shadowImage = ima;
    
    self.tabBar.backgroundColor = SLIVERYCOLOR;

第十二.判斷字符串中是否含有中文

    -(BOOL)isChinese:(NSString *)str{
        NSString *match=@"(^[\u4e00-\u9fa5]+$)";
        NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF matches %@", match];
        return [predicate evaluateWithObject:str];
    }

第十三.解決父視圖和子視圖的手勢沖突

    /** 解決手勢沖突 */
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
        if ([touch.view isDescendantOfView:cicView]) {
            return NO;
        }
        return YES;
    }

第十四.NSDate與NSString的相互轉(zhuǎn)化

    -(NSString *)dateToString:(NSDate *)date {
      // 初始化時間格式控制器
      NSDateFormatter *matter = [[NSDateFormatter alloc] init];
      // 設(shè)置設(shè)計格式
      [matter setDateFormat:@"yyyy-MM-dd hh:mm:ss zzz"];
      // 進(jìn)行轉(zhuǎn)換
      NSString *dateStr = [matter stringFromDate:date];
      return dateStr;
    }
    -(NSDate *)stringToDate:(NSString *)dateStr {
    
      // 初始化時間格式控制器
      NSDateFormatter *matter = [[NSDateFormatter alloc] init];
      // 設(shè)置設(shè)計格式
      [matter setDateFormat:@"yyyy-MM-dd hh:mm:ss zzz"];
      // 進(jìn)行轉(zhuǎn)換
      NSDate *date = [matter dateFromString:dateStr];
      return date;
    }

第十五.Xcode 8 注釋設(shè)置

    打開終端捉蚤,命令運(yùn)行: sudo /usr/libexec/xpccachectl
    然后必須重啟電腦后生效

十六.刪除storyboard的方法

    一般情況下抬驴,我們有時候不想用storyboard,但是直接刪除的話缆巧,Xcode就會報錯布持。那我今天就來講一下,正確刪除storyboard的方法陕悬。
    
    第一题暖,直接將工程中的storyboard直接刪除掉,這樣你覺得就OK了捉超?你錯了胧卤,還是要有第二步的。
    
    第二拼岳,找到plist文件枝誊,將plist文件中的Main storyboard file base name刪除掉,如圖所示

十七.ASCII 和 NSString 的相互轉(zhuǎn)換

    // NSString to ASCII
    NSString *string = @"A";
    int asciiCode = [string characterAtIndex:0]; //65
    
    //ASCII to NSString
    int asciiCode = 65;
    NSString *string =[NSString stringWithFormat:@"%c",asciiCode]; //A

十八.獲取當(dāng)前連接的wifi名稱

        NSString *wifiName = @"Not Found";

        CFArrayRef myArray = CNCopySupportedInterfaces();
    
        if (myArray != nil) {
    
            CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
    
            if (myDict != nil) {
    
                NSDictionary *dict = (NSDictionary*)CFBridgingRelease(myDict);
    
                wifiName = [dict valueForKey:@"SSID"];
    
            }
    
        }
    
        NSLog(@"wifiName:%@", wifiName);

十九.蘋果自帶的下拉刷新方法

        //設(shè)置下拉刷新 UIRefreshControl *refresh = [[UIRefreshControl alloc] init];

        NSDictionary dict = @{NSForegroundColorAttributeName:[UIColor redColor]}; 
        NSAttributedString string = [[NSAttributedString alloc] initWithString:@"幫你署最新惜纸。叶撒。" attributes:dict]; 
        refresh.attributedTitle = string;

        [self.tableView addSubview:refresh];

二十.顯示和隱藏系統(tǒng)文件

        顯示Mac隱藏文件的命令:

        defaults write com.apple.finder AppleShowAllFiles -bool true
        
        隱藏Mac隱藏文件的命令:
        
        defaults write com.apple.finder AppleShowAllFiles -bool false

二十一.跨控制器跳轉(zhuǎn)返回

    for (UIViewController *controller in self.navigationController.viewControllers) { 
        if ([controller isKindOfClass:[@“你要返回的控制器類名” class]]) {
             [self.navigationController popToViewController:controller animated:YES];
         }
     }

二十二. layer.cornerRadius 圓角流暢性的優(yōu)化

第一種:CornerRadius

    loginBtn.layer.cornerRadius = 10;
    loginBtn.layer.shouldRasterize = YES;
    loginBtn.layer.rasterizationScale = [UIScreen mainScreen].scale;

第二種:UIBezierPath 和 CAShapeLayer

    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_draw.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:_draw.bounds.size];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc]init];
    // 設(shè)置大小
    maskLayer.frame = _draw.bounds;
    // 設(shè)置圖形樣子
    maskLayer.path = maskPath.CGPath;
    _draw.layer.mask = maskLayer;

第三種:設(shè)置上半部分圓角

    _titleLabel.layer.masksToBounds = YES;

    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.path = [UIBezierPath bezierPathWithRoundedRect:_titleLabel.bounds byRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: (CGSize){5.0f, 5.0f}].CGPath;
    
    _titleLabel.layer.mask = maskLayer;

二十三.導(dǎo)航欄和下方視圖間隔距離消失 以及 導(dǎo)航欄和下方視圖不重疊

    //不間隔
    self.automaticallyAdjustsScrollViewInsets=YES;

    //不重疊
    self.edgesForExtendedLayout = UIRectEdgeNone

二十四.毛玻璃效果(ios8.0以后的版本)

    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    visualEffectView.frame = CGRectMake(0, 0, 320*[FlexibleFrame ratio], 180*[FlexibleFrame ratio]);
    visualEffectView.alpha = 1.0;

二十五.工作中常用的第三方

傳送

二十六.PCH文件中的小玩意

    創(chuàng)建.pch文件時 , BuildSetting 中的 Prefix Header 中的路徑開頭可以寫  $(SRCROOT)/工程地址, 這樣寫的好處可以使你的挪動代碼不用手動更換路徑!

二十七.如何點(diǎn)擊谷歌地圖獲取所在位置經(jīng)緯度?

鏈接

    調(diào)用谷歌地圖 mapView:didTapAtCoordinate:  方法,即可獲得!

二十八.AppIcon 和 launch image 尺寸相關(guān)

傳送

** 二十九.iO中判斷兩個數(shù)組是否相同**

    NSArray *array1 = [NSArray arrayWithObjects:@"a", @"b", @"c",  nil];
    NSArray *array2 = [NSArray arrayWithObjects:@"d", @"a", @"c",  nil];
    bool bol = false;
    
    //創(chuàng)建倆新的數(shù)組
    NSMutableArray *oldArr = [NSMutableArray arrayWithArray:array1];
    NSMutableArray *newArr = [NSMutableArray arrayWithArray:array2];
    
    //對數(shù)組1排序。
    [oldArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2){
        return obj1 > obj2;
    }];
    
    //對數(shù)組2排序耐版。
    [newArr sortUsingComparator:^NSComparisonResult(id obj1, id obj2){
        return obj1 > obj2;
    }];
    
    if (newArr.count == oldArr.count) {
        
        bol = true;
        for (int16_t i = 0; i < oldArr.count; i++) {
            
            id c1 = [oldArr objectAtIndex:i];
            id newc = [newArr objectAtIndex:i];
            
            if (![newc isEqualToString:c1]) {
                bol = false;
                break;
            }
        }
    }
    
    if (bol) {
        NSLog(@" ------------- 兩個數(shù)組的內(nèi)容相同祠够!");
    }
    else {
        NSLog(@"-=-------------兩個數(shù)組的內(nèi)容不相同!");
    }

三十.屏幕渲染--顏色漸變

        CAGradientLayer *gradientLayer = [CAGradientLayer layer];
        gradientLayer.colors = @[(__bridge id)[UIColor whiteColor].CGColor,(__bridge id)[UIColor grayColor].CGColor,(__bridge id)[UIColor whiteColor].CGColor];
        gradientLayer.locations = @[@0.2,@0.65,@0.75];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1.0, 0);
        gradientLayer.frame = CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 2);
        [self.view.layer addSublayer:gradientLayer];

三十一.快速求和粪牲,最大值古瓤,最小值,平均值

    NSArray *array = [NSArray arrayWithObjects:@"2.0", @"2.3", @"3.0", @"4.0", @"10", nil]; 
    CGFloat sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue]; 
    CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue]; 
    CGFloat max =[[array valueForKeyPath:@"@max.floatValue"] floatValue]; 
    CGFloat min =[[array valueForKeyPath:@"@min.floatValue"] floatValue];

三十二.對比時間差

Paste_Image.png
    -(int)max:(NSDate *)datatime
    {
        //創(chuàng)建日期格式化對象
        NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
        NSDate *  senddate=[NSDate date];
        NSString *  locationString=[dateFormatter stringFromDate:senddate];
        NSDate *date=[dateFormatter dateFromString:locationString];
        //取兩個日期對象的時間間隔:
        //這里的NSTimeInterval 并不是對象虑瀑,是基本型湿滓,其實(shí)是double類型滴须,是由c定義的:typedef double NSTimeInterval;
        NSTimeInterval time=[date timeIntervalSinceDate:datatime];
        int days=((int)time)/(3600*24);
        return days;
    }

三十三.請求定位權(quán)限以及定位屬性

    _在地圖頁面放入下面代碼:_
        //定位管理器
        _locationManager=[[CLLocationManager alloc]init];
        //如果沒有授權(quán)則請求用戶授權(quán)
        if ([CLLocationManager authorizationStatus]==kCLAuthorizationStatusNotDetermined){
            [_locationManager requestWhenInUseAuthorization];
        }else if([CLLocationManager authorizationStatus]==kCLAuthorizationStatusAuthorizedWhenInUse){
            //設(shè)置代理
            _locationManager.delegate=self;
            //設(shè)置定位精度
            _locationManager.desiredAccuracy=kCLLocationAccuracyBest;
            //定位頻率,每隔多少米定位一次
            CLLocationDistance distance=10.0;//十米定位一次
            _locationManager.distanceFilter=distance;
            //啟動跟蹤定位
            [_locationManager startUpdatingLocation];
        }

三十四.將幾張圖片合成為一張

    - (UIImage *)composeWithHeader:(UIImage *)header content:(UIImage *)content footer:(UIImage *)footer{
        CGSize size = CGSizeMake(content.size.width, header.size.height +content.size.height +footer.size.height);
        UIGraphicsBeginImageContext(size);
        [header drawInRect:CGRectMake(0,
                                      0,
                                      header.size.width,
                                      header.size.height)];
        [content drawInRect:CGRectMake(0,
                                       header.size.height,
                                       content.size.width,
                                       content.size.height)];
        [footer drawInRect:CGRectMake(0,
                                      header.size.height+content.size.height,
                                      footer.size.width,
                                      footer.size.height)];
     
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;
}

三十五.按鈕的選擇狀態(tài)及與BarButton的結(jié)合使用

      self.barRightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        self.barRightBtn.frame = CGRectMake(WIDTH-20, 30, 80, 30);
        [self.barRightBtn setTitle:@"停止掃描" forState:UIControlStateNormal];
        [self.barRightBtn setTitle:@"開始掃描" forState:UIControlStateSelected];
    
        [self.barRightBtn setTitleColor:BLUECOLOR forState:UIControlStateNormal];
        self.barRightBtn.titleLabel.font = [UIFont systemFontOfSize:18];
        [[self.barRightBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
            self.barRightBtn.selected = !self.barRightBtn.selected;
            
            if (self.barRightBtn.selected) {
                [self endScanIbeacon];
            }else{
                [self startScanIbecan];
            }
        }];
        
        UIBarButtonItem *barBtn = [[UIBarButtonItem alloc] initWithCustomView:self.barRightBtn];
        self.navigationItem.rightBarButtonItem = barBtn;

三十六.自定義ttf字體

    1.將xx.ttf字體庫加入工程里;
FAA2B395-A0C2-4E61-9AC0-9F1967DD0CAA.png
    2.在工程的xx-Info.plist文件中新添加一行Fonts provided by application舌狗,加上字體庫的名稱;
Paste_Image.png
    3.引用字體庫的名稱,設(shè)置字體: [UIFontfontWithName:@"fontname" size:24];
Paste_Image.png
    4.如果不知道字體名稱扔水,可以遍歷字體進(jìn)行查詢;或者選中項(xiàng)目中的導(dǎo)入字體痛侍,然后showInFinder,雙擊打開查看最上面的字體介紹:

         for(NSString *fontfamilyname in [UIFont familyNames])  
      {  
          NSLog(@"family:'%@'",fontfamilyname);  
          for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])  
          {  
              NSLog(@"\tfont:'%@'",fontName);  
          }  
          NSLog(@"-------------");  
      }  

三十七.導(dǎo)航欄字體顏色改變

有時候想改變某個控制器中狀態(tài)欄的字體顏色,單純的在控制器添加 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent],發(fā)現(xiàn)添加后無改變!這時候就需要設(shè)置另外一個屬性!

    1.在 info.plist 中,將 View controller-based status bar appearance 設(shè)為 NO;
    2. 在對應(yīng)控制器添加[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

三十八.類似于 modal 效果的彈出視圖

        //初始化
       PopView *pop = [[PopView alloc] initWithFrame:CGRectMake(0, HEIGHT, WIDTH, HEIGHT-150)];
        pop.bgImaView.image = [UIImage imageNamed:[NSString stringWithFormat:@"backgaund_%ld",(long)index]];
        [self.view addSubview:pop];

        //點(diǎn)擊后frame改變,動畫展示上滑 (類似于 btn 點(diǎn)擊事件)
        [UIView animateWithDuration:0.5 animations:^{
            pop.frame = CGRectMake(0, 150, WIDTH, HEIGHT-150);
        }];

        //在點(diǎn)擊改變frame,動畫展示下滑
        [UIView animateWithDuration:0.5 animations:^{
            pop.frame = CGRectMake(0, HEIGHT, WIDTH, HEIGHT-150);
        }];

三十九.masonry 動畫效果有時候不實(shí)現(xiàn)需要添加此方法

Paste_Image.png

四十.設(shè)置手機(jī)聲音震動

    #import <AudioToolbox/AudioToolbox.h>
    #import <UIKit/UIKit.h>  
    - (void)vibrate   {    
          AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

**四十一.判斷一個點(diǎn)是否在一個區(qū)域魔市,判斷一個區(qū)域是否在一個區(qū)域 **

   1.CGRect 和 CGPoint 對比 (判斷一個點(diǎn)是否在一個區(qū)域)

        BOOL a = CGRectContainsPoint(_view.frame, point)

   2.CGRect 和 CGRect 對比 (判斷一個區(qū)域是否在一個區(qū)域)

        BOOL b = CGRectContainsRect(_view.frame,_btn.frame)

   3. CGPoint 和 CGPoint 對比 (判斷兩個點(diǎn)是否相同)

        BOOL c = CGPointEqualToPoint(point1, point2);

四十二,圖片的簡單壓縮

      1.  //背景視圖 (此種壓縮有白邊出現(xiàn))
        UIImageView *bgIma = [[UIImageView alloc] initWithFrame:BOUNDS];
        NSString *bgFile = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath,@"zsBg.png"]; //圖片緩存處理
        UIImage *image = [[UIImage alloc] initWithContentsOfFile:bgFile];
        NSData *data = UIImageJPEGRepresentation(image, 1.0);
        bgIma.image = [UIImage imageWithData:data];
        [self addSubview:bgIma];

      2.封裝方法
    - (UIImage *)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize
    {
        // Create a graphics image context
        UIGraphicsBeginImageContext(newSize);
        // Tell the old image to draw in this new context, with the desired
        // new size
        [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
        // Get the new image from the context
        UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
        // End the context
        UIGraphicsEndImageContext();
        // Return the new image.
        return newImage;
    }

    ((UIImageView *)view).image = [self imageWithImage:[UIImage imageNamed:self.notiArr[index]] scaledToSize:CGSizeMake(WIDTH-20, HEIGHT-64-10-180)] ;

** 四十三.橫豎屏詳細(xì)相關(guān)(全局豎屏,特殊控制器橫屏)**

    1.點(diǎn)項(xiàng)目 - Targets - General - Deployment Info 滞项,如圖
C70563D6-8465-4F95-A2BA-B26519663417.png
    2.在 appdelegate 頭文件中添加屬性

        /// 判斷是否橫豎屏
        @property (nonatomic,assign)BOOL allowRotation;

    3.在 appdelegate 實(shí)現(xiàn)文件中實(shí)現(xiàn)方法

        /* 橫豎屏 */
        - (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
            if (self.allowRotation) {
                return  UIInterfaceOrientationMaskAllButUpsideDown;
            }
            return UIInterfaceOrientationMaskPortrait;
        }

    4.在需要橫屏的文件中筹麸,導(dǎo)入頭文件 #import "AppDelegate.h" ,添加如此代碼

        /// 橫豎屏相關(guān)
        AppDelegate *app =(AppDelegate *)[[UIApplication sharedApplication] delegate];
        app.allowRotation = YES;

四十四.后臺無線定位

3754AB9E-4846-4668-ABB4-287C78C229A2.png

四十五.使用Xcode查找項(xiàng)目中的中文字符串,以方便實(shí)現(xiàn)國際化的需求

    1.打開”Find Navigator” (小放大鏡模樣 --- > ??)
    2.切換搜索模式到 “Find > Regular Expression”
    3.輸入@"[^"]*[\u4E00-\u9FA5]+[^"\n]*?" (swift請去掉”@” 輸入@"[^"]*[\u4E00-\u9FA5]+[^"\n]*?" 就好了)  

四十六.判斷 iOS 系統(tǒng)版本

    _判斷 iOS 系統(tǒng)版本大于10_

    #define IOS_VERSION_10 (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_9_x_Max)?(YES):(NO)  

    _判斷 iOS系統(tǒng)具體版本_

    1.預(yù)編譯文件(.pch文件)定義
    #define iPHONEType struct utsname systemInfo;uname(&systemInfo);

    引用
    iPHONEType
    NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding];

    2.[UIDevice currentDevice].systemVersion.floatValue ,例如:
    
        if ([UIDevice currentDevice].systemVersion.floatValue < 7.0f) {
                Method newMethod = class_getInstanceMethod(self, @selector(compatible_setSeparatorInset:));
                // 增加Dummy方法
                class_addMethod(
                        self,
                        @selector(setSeparatorInset:),
                        method_getImplementation(newMethod),
                        method_getTypeEncoding(newMethod));
            }

四十七.判斷 label 文字行數(shù)

    - (NSArray *)getLinesArrayOfStringInLabel:(UILabel *)label{
            NSString *text = [label text];
            UIFont *font = [label font];
            CGRect rect = [label frame];
        
            CTFontRef myFont = CTFontCreateWithName(( CFStringRef)([font fontName]), [font pointSize], NULL);
            NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
            [attStr addAttribute:(NSString *)kCTFontAttributeName value:(__bridge  id)myFont range:NSMakeRange(0, attStr.length)];
            CFRelease(myFont);
            CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString(( CFAttributedStringRef)attStr);
            CGMutablePathRef path = CGPathCreateMutable();
            CGPathAddRect(path, NULL, CGRectMake(0,0,rect.size.width,100000));
            CTFrameRef frame = CTFramesetterCreateFrame(frameSetter, CFRangeMake(0, 0), path, NULL);
            NSArray *lines = ( NSArray *)CTFrameGetLines(frame);
            NSMutableArray *linesArray = [[NSMutableArray alloc]init];
            for (id line in lines) {
                CTLineRef lineRef = (__bridge  CTLineRef )line;
                CFRange lineRange = CTLineGetStringRange(lineRef);
                NSRange range = NSMakeRange(lineRange.location, lineRange.length);
                NSString *lineString = [text substringWithRange:range];
                CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr, lineRange, kCTKernAttributeName, (CFTypeRef)([NSNumber numberWithFloat:0.0]));
                CFAttributedStringSetAttribute((CFMutableAttributedStringRef)attStr, lineRange, kCTKernAttributeName, (CFTypeRef)([NSNumber numberWithInt:0.0]));
                //NSLog(@"''''''''''''''''''%@",lineString);
                [linesArray addObject:lineString];
            }
        
            CGPathRelease(path);
            CFRelease( frame );
            CFRelease(frameSetter);
            return (NSArray *)linesArray;
        }

四十八.性能優(yōu)化的小玩意 (Debug模式)

    1. Product→Scheme→Edit Scheme 中 Run - Arguments - Environment Variables 設(shè)置Name為OS_ACTIVITY_MODE,Value為disable; //去除Xcode無效數(shù)據(jù),也就是 去除 所有 NSLog 打印信息

    2.寫到 .PCH 文件中 ,用來代替工程中的 NSLog 打印

        #ifdef DEBUG
        #define SLog(format, ...) printf("class: <%p %s:(%d) > method: %s \n%s\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String] )
        #else
        #define SLog(format, ...)
        #endif 

    3. release模式下 系統(tǒng)自動注釋slog , 以便于優(yōu)化性能

四十九.篩選字符串(去除空格 換行符 回車符 首尾兩端)

    - (NSString *)returnCustomString:(NSString *)string
    {
        [[[[[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] stringByReplacingOccurrencesOfString:@"/r" withString:@""] stringByReplacingOccurrencesOfString:@"/n" withString:@""] stringByReplacingOccurrencesOfString:@" " withString:@""] stringByReplacingOccurrencesOfString:@"/tab" withString:@""];
        
        return string;
    }

五十.數(shù)組和字典打印輸出中文(新建一個分類将宪,粘貼如下代碼)

    @implementation NSDictionary (LOG)

    - (NSString *)descriptionWithLocale:(id)locale
    {
        // 1.定義一個可變的字符串, 保存拼接結(jié)果
        NSMutableString *strM = [NSMutableString string];
        [strM appendString:@"{\n"];
        // 2.迭代字典中所有的key/value, 將這些值拼接到字符串中
        [self enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
            [strM appendFormat:@"\t%@ = %@,\n", key, obj];
        }];
        [strM appendString:@"}"];
        
        // 刪除最后一個逗號
        if (self.allKeys.count > 0) {
            NSRange range = [strM rangeOfString:@"," options:NSBackwardsSearch];
            [strM deleteCharactersInRange:range];
        }
        
        // 3.返回拼接好的字符串
        return strM;
    }
    
    
    @end
    
    
    @implementation NSArray (LOG)
    - (NSString *)descriptionWithLocale:(id)locale
    {
        // 1.定義一個可變的字符串, 保存拼接結(jié)果
        NSMutableString *strM = [NSMutableString string];
        [strM appendString:@"(\n"];
        // 2.迭代字典中所有的key/value, 將這些值拼接到字符串中
        [self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            [strM appendFormat:@"\t%@,\n", obj];
        }];
        [strM appendString:@")\n"];
        
        // 刪除最后一個逗號
        if (self.count > 0) {
            NSRange range = [strM rangeOfString:@"," options:NSBackwardsSearch];
            [strM deleteCharactersInRange:range];
        }
        
        // 3.返回拼接好的字符串
        return strM;
    }
    @end

五十一 . 十六進(jìn)制轉(zhuǎn)十進(jìn)制

    - (NSString *)turn16to10:(NSString *)str {
        if (str.length>10) {
            str =[str substringFromIndex:str.length-10];
        }
        NSLog(@"字符=%@", str);
        unsigned long long result = 0;
        NSScanner *scanner = [NSScanner scannerWithString:str];
        [scanner scanHexLongLong:&result];
        NSString *tempInt =[NSString stringWithFormat:@"%llu", result];
        if (tempInt.length>7) {
            tempInt =[tempInt substringFromIndex:tempInt.length-7];
        }
        NSLog(@"數(shù)字=%@", tempInt);
        return tempInt;
    }

五十二.禁止蘋果自帶的側(cè)滑返回功能

第一種方法:
    1.在需要禁止的控制器里面關(guān)閉側(cè)滑返回
        - (void)viewDidAppear:(BOOL)animated  
        {  
            [super viewDidAppear:animated];  
            // 禁用返回手勢  
            if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {  
                self.navigationController.interactivePopGestureRecognizer.enabled = NO;  
            }  
        }  

    2.如果只是單個頁面關(guān)閉绘闷,其他頁面可以側(cè)滑返回

            - (void)viewWillDisappear:(BOOL)animated  
            {  
                [super viewWillDisappear:animated];  
                // 開啟返回手勢  
                if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {  
                    self.navigationController.interactivePopGestureRecognizer.enabled = YES;  
                }  
            }

第二種方法:

    -(void)popGestureChange:(UIViewController *)vc enable:(BOOL)enable{
          if ([vc.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
                //遍歷所有的手勢
                for (UIGestureRecognizer *popGesture in vc.navigationController.interactivePopGestureRecognizer.view.gestureRecognizers) {
              popGesture.enabled = enable;
                }
           }
    }
  這個函數(shù)的使用可以在viewDidAppear調(diào)用橡庞,調(diào)用完之后記得在viewDidDisappear恢復(fù)原先的設(shè)置

五十三、合并framework

    1.常規(guī)的需要合并 真機(jī)版framework 和模擬器版framework 印蔗,需要用到 lipo指令:lipo -create 真機(jī)版本路徑 模擬器版本路徑 -output 合并后的文件路徑 (注:空格不能省去)扒最!示例:

        路徑1:/Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/Products/Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework

        路徑2:/Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/Products/Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework

        合并后的路徑及名稱:/Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/IJKMediaFramework 

        lipo -create /Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/Products/Release-iphoneos/IJKMediaFramework.framework/IJKMediaFramework /Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/Products/Release-iphonesimulator/IJKMediaFramework.framework/IJKMediaFramework -output /Users/XXX/Library/Developer/Xcode/DerivedData/IJKMediaPlayer-giggdwtupptvcyalfbtxfhwssrix/Build/IJKMediaFramework 

    2.報錯及注意點(diǎn)

        1)指令之間的空格不能省去
        2)報錯:fatal error: can't map input file 

            原因是因?yàn)?framework 路徑格式輸入錯誤,需要將 xxxFramework.framework 改成 xxxFramework.framework/xxxFramework

        3)報錯:can't move temporary file

            原因是因?yàn)?合并后的 路徑格式輸入錯誤华嘹,需要在路徑后面加入合并后你起的文件名稱 吧趣,/Users/Zhuge_Su/Desktop 改成 /Users/Zhuge_Su/Desktop/xxx.framework  (xxx需要自己自定義)

五十四、更改 textfield 占位符 相關(guān)

       UIColor *color = [UIColor whiteColor];  
      _userName.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"用戶名" attributes:@{NSForegroundColorAttributeName: color}];

五十五耙厚、tableview 從第四行或者第五行顯示 解決方法

    在動態(tài)布局tableview行高的時候强挫,會出現(xiàn)tableview cell 從第四行或者第五行開始加載,解決方案:昨個判斷 如果動態(tài)行高大于0 顯示動態(tài)行高薛躬;如果動態(tài)行高等于0 纠拔,默認(rèn)返回一個 1或者 2值 ,舉例:

      - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
        if (self.totalCellHeight > 0) {
            return self.totalCellHeight;
        } else{
            return 1;
        }
        return 0;
    }

五十四.IPV6環(huán)境搭建

Enter your link description here:

五十五.加急審核鏈接

[ 鏈接 ](https://developer.apple.com/appstore/contact/appreviewteam/index.html)

五十六.上架審核的小注意點(diǎn)

1.檢查全局?jǐn)帱c(diǎn)是否都清除完畢;

2.檢查 EditScheme 是否都是release狀態(tài);

3.檢查所有數(shù)據(jù)是否包含 測試,demo 等中英文字樣;

4.檢查 后臺模式,去除掉不需要使用的后臺模式,尤其是定位相關(guān);相關(guān)文字描述要描述清楚;

5.為以防萬一,未開發(fā)的項(xiàng)目還是隱藏的好(看個人人品);

6.產(chǎn)品流程上,可點(diǎn)擊和不可點(diǎn)擊狀態(tài)要有不同顯示或者提示;

五十七.app在app store 上的地址

http://itunes.apple.com/cn/app/idXXXXXXXXXX?mt=8 (XXXXXXXXXX 是你app 在itunes connect上創(chuàng)建的app id)
itms-apps://itunes.apple.com/app/id1144099528

五十八泛豪、Xcode斷點(diǎn)失效解決方法

1.首先點(diǎn)擊菜單product->Debug workflow取消選中show Disassembly when debug 是否勾選,如果勾選點(diǎn)擊取消
圖片.png
2. Build Setting 中 Generate Debug Symbols 設(shè)置為 Yes
圖片.png
3.Build Setting中將`Enable Clang Module Debugging`設(shè)置為`NO`即可",

五十九稠诲、更改項(xiàng)目名字

傳送門

六十、下載Xcode中的版本

傳送門1
傳送門2

六十一诡曙、iPhone X tabbar重影

-(void)viewWillLayoutSubviews{
  [super viewWillLayoutSubviews];

  for (UIView *child in self.tabBarController.tabBar.subviews) {
      if ([child isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
          [child removeFromSuperview];
      }
  }

}

六十二臀叙、轉(zhuǎn)讓app

傳送門

六十三、蘋果開發(fā)者相關(guān)

 電話: 4006701855
 網(wǎng)址:https://developer.apple.com
 3.2.1審核相關(guān)網(wǎng)址:https://tieba.baidu.com/p/5659292532?red_tag=2857790889
                               https://www.cnblogs.com/zk1947/p/8425506.html

六十四价卤、iTerm 自動補(bǔ)全相關(guān)

打開終端劝萤,輸入 : 

  nano .inputrc

  在文件里面寫上:

  set completion-ignore-case on
  set show-all-if-ambiguous on
  TAB: menu-complete

  ctrl + o ,回車,重啟終端慎璧,自動補(bǔ)全按tap鍵就ok床嫌。

更改iterm2的顏色
傳送門

六十五、描述文件相關(guān)

       1.查看描述文件的位置

             所有的描述文件安裝后胸私,都保存在Provisioning Profiles目錄下厌处。完整路徑為:~/Library/MobileDevice/Provisioning Profiles


      2.查看描述文件的內(nèi)容

      在終端使用命令查看:/usr/bin/security cms -D -i 文件路徑 

六十六、如何解決“app已損壞岁疼,打不開阔涉。你應(yīng)該將它移到廢紙簍。

       命令行運(yùn)行:
      修改系統(tǒng)配置:系統(tǒng)偏好設(shè)置… -> 安全性與隱私捷绒。修改為任何來源
      如果沒有這個選項(xiàng)的話 ,打開終端瑰排,執(zhí)行

      sudo spctl --master-disable 
      sudo spctl --master-disable Rference

六十七、新建Xcode指定默認(rèn)類名前綴

51530583gw1eqccvyqgd1j20ow0sednl.jpg

六十八暖侨、測試iOS版的App注意事項(xiàng)

      1椭住、app使用過程中,接聽電話字逗,可以測試不同的通話時間的長短京郑,對于通話結(jié)束后显押,原先打開的app的響應(yīng),比如是否停留在原先界面傻挂,繼續(xù)操作時的相應(yīng)速度等乘碑。
      2、app使用過程中金拒,有推送消息時兽肤,對app的使用影響。
      3绪抛、設(shè)備在充電時资铡,app的響應(yīng)以及操作流暢度。
      4幢码、設(shè)備在不同電量時(低于10%笤休,50%95%),app的響應(yīng)以及操作流暢度
      5症副、意外斷電時店雅,app數(shù)據(jù)丟失情況
      6、網(wǎng)絡(luò)環(huán)境變化時贞铣,app的應(yīng)對情況如何:是否有是當(dāng)提示闹啦?從有網(wǎng)絡(luò)環(huán)境到無網(wǎng)絡(luò)環(huán)境時,app的反饋如何辕坝?從無網(wǎng)絡(luò)環(huán)境回到有網(wǎng)絡(luò)環(huán)境時窍奋,是否能自動加載數(shù)據(jù),多久才能開始加載數(shù)據(jù)
      7酱畅、多點(diǎn)觸摸的情況
      8琳袄、跟其他app之間互相切換時的響應(yīng)
      9、進(jìn)程關(guān)閉再重新打開的反饋
      10纺酸、iOS系統(tǒng)語言環(huán)境變化時

六十九窖逗、QQ ID 轉(zhuǎn) 十六進(jìn)制

echo 'ibase=10;obase=16;101553465'|bc

七十、查看cocoapods版本和.a版本

pod search GoogleWebRTC (查看cocoapods下三方版本)
lipo -info XXX.a (cd到.a目錄下吁峻,輸出指令)

七十一滑负、查看cocoapods版本和.a版本

self.areaIcon.image = [[UIImage imageNamed:@"ico_title_city.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
self.areaIcon.tintColor = [UIColor whiteColor];

七十二、根據(jù)滾動距離調(diào)整導(dǎo)航視圖透明度

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

    CGFloat y = scrollView.contentOffset.y;
    self.navBarContainer.alpha = y/(546 * (kDeviceWidth / 750.0) - MSUNavHeight);
    CGFloat alpha = self.navBarContainer.alpha * 3;
    self.leftButton.alpha = 1 - alpha;
}

七十三用含、當(dāng)前頁面設(shè)置后切換整個App設(shè)置

1.不含子視圖的切換 (項(xiàng)目視圖層級比較多,所以多了一層)

MSUMainTabbarController *tab = [[MSUMainTabbarController alloc] init];
tab.selectedIndex = 3;

MSUMainNavigationController *mainNav = (MSUMainNavigationController *)tab.selectedViewController;
TUNewPersonController *new = (TUNewPersonController *)mainNav.visibleViewController;
new.selectedIndex = index;

///解決動畫bug
dispatch_async(dispatch_get_main_queue(), ^{
    [[[UIApplication sharedApplication] delegate] window].rootViewController = tab;
    //一些UI提示帮匾,可以提供更友好的用戶交互(也可以刪掉)
    [SVProgressHUD showWithStatus:@"正在切換"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
});

2.包含子視圖的切換(項(xiàng)目視圖層級比較多啄骇,所以多了一層)

MSUMainTabbarController *tab = [[MSUMainTabbarController alloc] init];
tab.selectedIndex = 3;

MSUMainNavigationController *mainNav = (MSUMainNavigationController *)tab.selectedViewController;
TUNewPersonController *new = (TUNewPersonController *)mainNav.visibleViewController;
new.selectedIndex = 0;

MSUMainNavigationController *newNav = (MSUMainNavigationController *)new.selectedViewController;

TUPersonSettingController *set = [[TUPersonSettingController alloc] init];
TULampSetController *lamp = [[TULampSetController alloc] init];
newNav.viewControllers = @[set,lamp];

///解決動畫bug
dispatch_async(dispatch_get_main_queue(), ^{
    g_window.rootViewController = tab;
    [[NSNotificationCenter defaultCenter] postNotificationName:TUSettingChange object:nil];
    //一些UI提示,可以提供更友好的用戶交互(也可以刪掉)
    [SVProgressHUD showWithStatus:@"正在切換"];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
});

七十四瘟斜、多Configuration配置環(huán)境

1.在Project - Info - Configuration 新增需要的configuration環(huán)境
圖片.png
2.在PODS - Info - Configuration  新增需要的configuration環(huán)境
圖片.png
3.pod install 后 缸夹,查看Project 和 PODS 里面的Build setting 對應(yīng)的Preproessor Macro 里面的鍵值對
圖片.png
4.使用
圖片.png

七十五痪寻、大文件下載 -- lfs

 brew install git-lfs
 git lfs install

下載鏈接

七十六、xcode搜索<replace>漢字替換正則匹配
1.@".[\u4e00-\u9fa5]+."
2.:@"["]*[\u4E00-\u9FA5]+["\n]?"
3.@"[^"]
[\u4E00-\u9FA5]+[^"\n]?"
4.(@"[^"]
[\u4E00-\u9FA5]+[^"\n]*?")
LCLocalizedString(nil, $1)

image.png

七十七虽惭、查詢某個framework是否支持bitcode

otool -l framework二進(jìn)制文件地址 | grep __LLVM | wc -l
為0表示不支持
image.png

七十八橡类、label的展開和收起

 /// 是否展示展開/收起
- (void)setupAddMoreBtn
{
  BOOL isShowAll = self.model.isShowAll;
  self.contentLabel.numberOfLines = isShowAll ? 0 : 2;

  NSString *contentStr = self.model.content;
  if ([LCPathTools checkIsJsonString:self.model.content]) {
      LCCommunityContentModel *contentModel = [LCCommunityContentModel yy_modelWithJSON:self.model.content];
      contentStr = contentModel.content;
  }
  NSMutableAttributedString *attStr = [self getFinalContentStrWithContent:contentStr];
  YYTextLayout *layoutWidth = [YYTextLayout layoutWithContainerSize:CGSizeMake(LCDeviceWidth - LC_X(87), CGFLOAT_MAX) text:attStr.copy];

  if (layoutWidth.rowCount > 2) {
    NSString *str = isShowAll ? LCLocalizedString(@"App_domestic_2501", @"收起") : LCLocalizedString(@"App_domestic_3237", @"展開");
    NSMutableAttributedString *showAtt = [self getFinalContentStrWithContent:[NSString stringWithFormat:@"...    %@", str]];
    if (isShowAll) {
        showAtt = [self getFinalContentStrWithContent:[NSString stringWithFormat:@"    %@", str]];
    }
    
    NSRange expandRange = [showAtt.string rangeOfString:str];
    [showAtt addAttribute:NSForegroundColorAttributeName value:[LCApperance mainYellowColor] range:expandRange];
    
    YYTextHighlight *hi = [YYTextHighlight new];
    [showAtt yy_setTextHighlight:hi range:expandRange];
    MJWeakSelf;
    hi.tapAction = ^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
        weakSelf.model.isShowAll = !isShowAll;
        [weakSelf setupAddMoreBtn];
    };
    
    if (isShowAll) {
        [attStr appendAttributedString:showAtt];
        self.contentLabel.truncationToken = nil;
    } else {
        YYLabel *seeMore = [YYLabel new];
        seeMore.attributedText = showAtt;
        [seeMore sizeToFit];
        
        NSAttributedString *truncationToken = [NSAttributedString yy_attachmentStringWithContent:seeMore contentMode:UIViewContentModeRight attachmentSize:showAtt.size  alignToFont:showAtt.yy_font alignment:YYTextVerticalAlignmentCenter];
        self.contentLabel.truncationToken = truncationToken;
    }
    YYTextLayout *layoutWidth = [YYTextLayout layoutWithContainerSize:CGSizeMake(LCDeviceWidth - LC_X(87), CGFLOAT_MAX) text:attStr.copy];
    
    //文本高度
    CGFloat contentH = layoutWidth.textBoundingSize.height;
    CGFloat scrollH = contentH;
    
    // 最大限制<場景分帶鏈接和不帶鏈接>
    CGFloat linkH = self.leftImageView.isHidden ? 0 : LC_DeviceX(24);
    CGFloat maxLimit = [LCPathTools checkIsJsonString:self.model.content] ? LC_DeviceX(112)+linkH : LC_DeviceX(136)+linkH;

    if (isShowAll) {
        if (contentH > maxLimit) {
            scrollH = maxLimit;
        }
    } else {
        if (contentH > LC_X(44)) {
            scrollH = LC_X(40)+linkH;
            contentH = LC_X(40);
        }
    }
    [self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(scrollH);
    }];
    [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(contentH);
        make.bottom.equalTo(self.scrollView.mas_bottom).offset(-linkH);
    }];
  } else {
    CGFloat linkH = self.leftImageView.isHidden ? 0 : LC_DeviceX(24);
    [self.scrollView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(44+linkH);
    }];
    [self.contentLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(44);
    }];
  }
  self.contentLabel.attributedText = attStr;
}

七十九、Xcode15 iOS17模擬器文件安裝命令

 xcrun simctl runtime add iOS_17_Simulator_Runtime.dmg
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末芽唇,一起剝皮案震驚了整個濱河市顾画,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌匆笤,老刑警劉巖研侣,帶你破解...
    沈念sama閱讀 218,122評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異炮捧,居然都是意外死亡庶诡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,070評論 3 395
  • 文/潘曉璐 我一進(jìn)店門咆课,熙熙樓的掌柜王于貴愁眉苦臉地迎上來末誓,“玉大人,你說我怎么就攤上這事书蚪』裕” “怎么了?”我有些...
    開封第一講書人閱讀 164,491評論 0 354
  • 文/不壞的土叔 我叫張陵善炫,是天一觀的道長撩幽。 經(jīng)常有香客問我,道長箩艺,這世上最難降的妖魔是什么窜醉? 我笑而不...
    開封第一講書人閱讀 58,636評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮艺谆,結(jié)果婚禮上榨惰,老公的妹妹穿的比我還像新娘。我一直安慰自己静汤,他們只是感情好琅催,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,676評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著虫给,像睡著了一般藤抡。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上抹估,一...
    開封第一講書人閱讀 51,541評論 1 305
  • 那天缠黍,我揣著相機(jī)與錄音,去河邊找鬼药蜻。 笑死瓷式,一個胖子當(dāng)著我的面吹牛替饿,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播贸典,決...
    沈念sama閱讀 40,292評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼视卢,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了廊驼?” 一聲冷哼從身側(cè)響起据过,我...
    開封第一講書人閱讀 39,211評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蔬充,沒想到半個月后蝶俱,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,655評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡饥漫,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,846評論 3 336
  • 正文 我和宋清朗相戀三年榨呆,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片庸队。...
    茶點(diǎn)故事閱讀 39,965評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡积蜻,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出彻消,到底是詐尸還是另有隱情竿拆,我是刑警寧澤,帶...
    沈念sama閱讀 35,684評論 5 347
  • 正文 年R本政府宣布宾尚,位于F島的核電站丙笋,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏煌贴。R本人自食惡果不足惜御板,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,295評論 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望牛郑。 院中可真熱鬧怠肋,春花似錦、人聲如沸淹朋。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,894評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽础芍。三九已至杈抢,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間者甲,已是汗流浹背春感。 一陣腳步聲響...
    開封第一講書人閱讀 33,012評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留虏缸,地道東北人鲫懒。 一個月前我還...
    沈念sama閱讀 48,126評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像刽辙,于是被迫代替她去往敵國和親窥岩。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,914評論 2 355