一、統一類前綴html
類的前綴,能夠這樣加點擊 target,在XCode最右側的欄目裏面會看到以下界面,在箭頭處填寫便可git
二、storyboard設置view的寬高比swift
假如要設置View的寬高比爲2:1
(1)先將view的frame調整爲2:1,好比width=200,height=100;
(2)勾選Aspect Ratioruby
三、storyboard中控件的約束線也能拖拽成屬性,方便代碼修改!多線程
四、類別(Category)和擴展(Extension)app
類別是類方法的擴展,不能添加屬性!可是能夠經過runtime進行添加函數
擴展就是在類中聲明屬性@propertyui
五、線程的死鎖和互斥編碼
死鎖:線程相互等待 例如: 同步主線程刷新!atom
互斥:多線程並行修改同一個資源 例如:賣票等!
六、weak修飾屬性時:當改屬性的引用計數爲0時,會將指針指向nil,底層實現就是hash表http://www.bijishequ.com/detail/314557?p=
七、ARC下OF(Core Foundation例如Core Graphics、Core Text)和OC對象的轉換須要用到__bridge,__bridge_transfer,__bridge_retained
八、獲取請求時間
CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();CFAbsoluteTime end = CFAbsoluteTimeGetCurrent();
NSLog(@"link in time %f",end - start)
九、Xcode 8.1或更高版本,在使用Editor中的Create NSManagedObject Subclass 這個命令的時候,須要先把這個model的Codegen設置爲Manual/None,不然會報錯,
十、修改文件爲 可執行: chmod +x 文件 ,先cd 到上一級文件夾;
十一、AFN默認對請求參數(NSMutableDictionary)內字段進行UTF-8編碼,直接發送字符串不行!
十二、iOS6.0以後廢棄ViewDidUnload方法!
1三、KVO的實現是isa混寫(isa-swizzling),建立新類並從新set方法,將isa指針指向這個新類!
1四、判斷當前是iPhone幾:
struct utsname systemInfo;
uname(&systemInfo); NSString *deviceString = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
1五、 正弦波
y=峯高* sin(x * M_PI / self.frame.size.width * 峯的數量 + 移動速度)
1六、touchBegin失效
建立UIScrollView 或 UIImageView 時,當點擊時UIScrollView 或 UIImageView 會截獲touch事件,致使touchesBegan: withEvent:/touchesMoved: withEvent:/touchesEnded: withEvent: 等方法不執行。解決辦法:當UIScrollView 或 UIImageView 截獲touch事件後,讓其傳遞下去便可(就是傳遞給其父視圖UIView)
1七、延遲函數的使用和取消(適用於屢次點擊同一個事件,彈框延遲消失)
- (void)performSelector:(SEL)aSelector withObject:(nullable id)anArgument afterDelay:(NSTimeInterval)delay;//延遲函數 + (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector:(SEL)aSelector object:(nullable id)anArgument;//取消延遲
1八、bounds的影響(CAScrollLayer就是經過改變本身的原點位置,影響子view的顯示)
(1)它能夠修改本身座標系的原點位置,影響「子view」的顯示位置。
(2) bounds,它能夠經過改變寬高,改變自身的frame,進而影響到再父視圖的顯示位置(平均擴充或縮減四周的區域)和大小。
1九、開發者團隊
20、開發者帳號
if (@available(iOS 8.2, *)) { //iOS 8.2版本以後 } else { }
2四、精簡代碼,返回最後一句的值
self.backScrollView.frame = ({ CGRect frame = self.backScrollView.frame; frame.origin.y = self.view.frame.origin.y - 10; frame; });
2五、子視圖自適應父視圖
@property(nonatomic) BOOL autoresizesSubviews; // default is YES. @property(nonatomic) UIViewAutoresizing autoresizingMask;
2六、獲取字符串中的數字
NSCharacterSet* nonDigits =[[NSCharacterSet decimalDigitCharacterSet] invertedSet]; int remainSecond =[[urlString stringByTrimmingCharactersInSet:nonDigits] intValue]; NSLog(@" num %d ",remainSecond);
2七、Objective-C Literals 字面量建立
NSArray *array = @[@"One String", @"Two"];
2八、建立Category分類
1、文件列表右鍵-->選擇New File... 2、選擇iOS-->Source -->Objective-C File 3、File:文件起名 File Type:文件類型Empty File(空文件)、Category(分類)、Protocol(協議)、Extension(擴展)
Class:類名
2九、三目運算符
rootID ?rootID: @"" 和 rootID ?: @"" 效果等同
30、gem sources 淘寶不在維護
https://gems.ruby-china.org/
3一、超出view部分擁有點擊事件,重寫view的hitTest withEvent事件
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event];
if (view == nil) {
for (UIView *subView in self.subviews) {
CGPoint tp = [subView convertPoint:point fromView:self];
if (CGRectContainsPoint(subView.bounds, tp)) {
view = subView;
}
}
}
return view;
}