iOS 專案問題
IOS安裝CocoaPods詳情過程https://www.tuicool.com/articles/3yAJR3i
HyPopMenuView模仿新浪微博彈出菜https://github.com/wwdc14/HyPopMenuView
iOS播放器、Flutter高仿書旗小說、卡片動畫、二維碼掃碼、選單彈窗效果等原始碼
https://www.tuicool.com/articles/YnuaaeiiOS 類似朋友圈的結構https://juejin.im/entry/589d28ab86b599006b2c0a1d
iOS 判斷當前網路狀態的三種方法https://www.tuicool.com/articles/qYJJru3
UIScrollView和UITableView手勢衝突的https://www.tuicool.com/articles/UnM3yuq
一行程式碼整合空白頁面佔位圖(runtime+MJRefresh)https://github.com/yangli-dev/LYEmptyView
iOS 自定義tabbar中間按鈕 超簡單方法https://www.tuicool.com/articles/VbI7Fnj
iOS---購物車https://www.tuicool.com/articles/f2EVJv
iOS開發之仿微信右上角彈窗(第三方)https://www.jianshu.com/p/9e152a6ebe9d
iOS 雙擊tabbar重新整理頁面https://www.tuicool.com/articles/aq2yYzi
APP顯示了使用者的排名被拒https://www.jianshu.com/p/eaf1fefe45b8
30分鐘摸透iOS中謂詞NSPredicate的來龍去脈https://www.tuicool.com/articles/2mMFNjR
開發微信支付之前要做的那些事兒https://www.tuicool.com/articles/6VVR3iu
iOS SQLite詳解https://www.tuicool.com/articles/36Z7jin
多個請求統一更新介面https://www.tuicool.com/articles/U7n2uur
iOS本地化 NSLocalizedString的使用(國際化語言)https://www.jianshu.com/p/3d77c2e76684
Aspect Ratio
Aspect Ratio:設定檢視的寬高比 檢視寬度隨著螢幕寬度變化拉伸時,讓其高度自動進行等比例拉伸.保持該檢視寬高比不變. 一般先確定寬度(6的尺寸),再設定寬高比利,
Device RGB
iOS色彩空間——xib和程式碼設定顏色的偏差問題在使用視覺化程式設計時, 在XIB或SB中直接設定顏色,選擇RGB Slider設定顏色時,Xcode 中預設勾選的是Generic RGB。 解決方式:選擇Device RGB,
//強與弱 __weak typeof(self) weakSelf = self; [self doSomeBlockJob:^{ __strong typeof(weakSelf) strongSelf = weakSelf; if (strongSelf) { ... } }];
tableView
//iOS 中關於列表滾動流暢方案的一些探討 //高度自適應 self.tableView.estimatedRowHeight = 88; self.tableView.rowHeight = UITableViewAutomaticDimension; //關於圓角 label.layer.cornerRadius = 5.f; label.clipsToBounds = YES; //合理使用 reuserIdentifier BLPayTopCell * topCell = [tableView dequeueReusableCellWithIdentifier:@"BLPayTopCell" forIndexPath:indexPath];
圓角優化:使用貝塞爾曲線UIBezierPath和Core Graphics框架畫出一個圓角
#import <UIKit/UIKit.h> @interface UIImageView (Category) + (UIImage *)imageWithRoundCorner:(UIImage *)sourceImage cornerRadius:(CGFloat)cornerRadius size:(CGSize)size; @end #import "UIImageView+Category.h" @implementation UIImageView (Category) + (UIImage *)imageWithRoundCorner:(UIImage *)sourceImage cornerRadius:(CGFloat)cornerRadius size:(CGSize)size{ CGFloat scale = [UIScreen mainScreen].scale; UIGraphicsBeginImageContextWithOptions(size, NO, scale); CGRect bounds = CGRectMake(0, 0, size.width, size.height); [[UIBezierPath bezierPathWithRoundedRect:bounds cornerRadius:cornerRadius] addClip]; [sourceImage drawInRect:bounds]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } @end
等比例縮放圖片
//img:為傳入的圖片;size:為放置圖片區域的大小;scaledImage:為返回壓縮後的圖片 + (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{ // 建立一個bitmap的context // 並把它設定成為當前正在使用的context UIGraphicsBeginImageContext(size); // 繪製改變大小的圖片 [img drawInRect:CGRectMake(0,0, size.width, size.height)]; // 從當前context中建立一個改變大小後的圖片 UIImage* scaledImage =UIGraphicsGetImageFromCurrentImageContext(); // 使當前的context出堆疊 UIGraphicsEndImageContext(); //返回新的改變大小後的圖片 return scaledImage; }
記憶體優化
1,圖片的讀取採用正確的方式 imageNamed: 會快取圖片,用它讀取頻繁用到的小圖片,最噁心的是不知道它到底什麼時候釋放。 imageWithContentsOfFile: 不快取圖片,適合一次性讀取的大圖片。 NSString *path = [[NSBuddle mainBuddle] pathForResource:@"resourceName" oftype@"resourceType"]; UIImage *image = [[UIImage imageWithContentsOfFile:path]; 2,imageWithContentsOfFile 、 Assets.xcassets 對於大的圖片且偶爾需要顯示的應放到工程目錄下,不要放到 Assets.xcassets 中; 並使用 imageWithContentsOfFile 載入不讓系統快取 對於經常需要展示的小圖片放到 Assets.xcassets 中讓系統快取,使用 imageNamed 載入 /// 這裡順便提一下 imageNamed: 和 imageWithContentsOfFile: 的區別,這兩個 API 都需要解碼,並且工作流程都是一致的。 不過imageNamed:會做快取處理,在下一次用到相同的資源時,就會從快取裡面讀取。而 imageWithContentsOfFile: 則不會。
資料庫問題
1 資料庫頻繁操作開啟關閉,手動開啟關閉鎖, 使用一個單例類操作資料庫 2 避免同時操作一個資源使用佇列序列方式
Appearance方法
我們通過UIAppearance設定一些UI的全域性效果,這樣就可以很方便的實現UI的自定義效果 又能最簡單的實現統一介面風格,但是需要注意使用細則: ** 1、控制元件遵守了UIAppearance協議,才能對控制元件進行appearance設定 2、只有被UI_APPEARANCE_SELECTOR這個巨集修飾的屬性才能使用appearance進行設定,其他屬性則不具備該功能 3、appearance設定需要在該控制顯示之前設定完成,否則可能無效 ** // 適配ios11 if (@available(iOS 11.0, *)){ [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; } // [[UITableView appearance] setEstimatedRowHeight:0]; [[UITableView appearance] setEstimatedSectionFooterHeight:0]; [[UITableView appearance] setEstimatedSectionHeaderHeight:0];
NSUserDefaults standardUserDefaults中在最後使用synchronize的作用
系統會儲存到該應用下的/Library/Preferences/gongcheng.plist檔案中。需要注意的是如果程式意外退出, NSUserDefaultsstandardUserDefaults資料不會被系統寫入到該檔案,所以, 要使用[[NSUserDefaultsstandardUserDefaults] synchronize]命令直接同步到檔案裡,來避免資料的丟失。 ///小插曲 - (void)test { NSDictionary *dict = @{@1: @"甲", @2: @"乙", @3: @"丙", @4: @"丁"}; [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"testKey"]; [[NSUserDefaults standardUserDefaults] synchronize]; } ///報錯 2018-04-16 10:55:04.573393+0800 text[1344:58370] [User Defaults] Attempt to set a non-property-list object { 3 = "\U4e19"; 2 = "\U4e59"; 1 = "\U7532"; 4 = "\U4e01"; } as an NSUserDefaults/CFPreferences value for key testKey ///why And although NSDictionary and CFDictionary objects allow their keys to be objects of any type, if the keys are not string objects, the collections are not property-list objects. 雖然 NSDictionary 和 CFDictionary 物件的 Key 可以為任何型別(只要遵循 NSCopying 協議即可), 但是如果當 Key 不為字串 string 物件時,此時這個字典物件就不能算是 property list objects 了,
捕捉異常
@try { ///關鍵程式碼 NSString *str = @"abc"; [str substringFromIndex:111]; // 程式到這裡會崩 } @catch (NSException *exception) { ///捕捉異常(彈框提示報錯了) NSLog(@"%s\n%@", __FUNCTION__, exception); NSLog(@"%@", exception.name); NSLog(@"%@", exception.reason); } @finally { ///資源回收完畢! NSLog(@"我一定會執行"); }
多用字面量語法,少用等價方法
// 字面量字串 NSString *str = @"QiShare"; // 字面量數值 NSNumber *num = @(1); NSNumber *floatNum = @(1.0); int x = 5; float y = 3.14; NSNumber *num = @(x * y); // 字面量陣列 NSArray *animals = @[@"cat", @"dog", @"tiger", @"monkey"]; NSString *cat = animals[0]; // 字面量字典 NSDictionary *qiShareDic = @{@"englishName": @"QiShare", @"chineseName": @"奇分享"}]; NSString *englishName = qiShareDic[@"englishName"]; NSString *chineseName = qiShareDic[@"chineseName"];