一、统一类前缀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;
}