iOS零碎知识
来源:互联网 发布:js改变div的style 编辑:程序博客网 时间:2024/04/28 11:49
1:子线程不能参与主线程的操作。。
犯过的错误----本想用此方法异步加载一张图片到主页。
<span style="font-size:18px;">[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response,NSData *data, NSError *connectionError) { UIImageView *imageview = [[UIImageView alloc]initWithFrame:self.view.bounds]; [self.view addSubview:imageview]; UIImage *image = [UIImage imageWithData:data]; imageview.image = image;}];</span>
但是他不起作用。就是因为此操作都是在子线程内
更改后的代码:
<span style="font-size:18px;">[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError) { dispatch_async(dispatch_get_main_queue(), ^{ UIImageView *imageview = [[UIImageView alloc]initWithFrame:self.view.bounds]; [self.view addSubview:imageview]; UIImage *image = [UIImage imageWithData:data]; imageview.image = image; });}];</span>
2:YES 当页面加载的第一个view是scrollview的时候会给scrollview留出navBar所占用的44像素
self.automaticallyAdjustsScrollViewInsets =YES;
3:避免block内的循环引用
一般使用
__weakViewController *blockSelf =self;或者
__weak typeof(self) blockSelf =self;
指向对象的弱引用。。。。
4:objc_msgSend 报错
我在使用MJRefresh的时候在这个方法这儿报错为此方法参数过多。
解决方法为在target选择Enable Strict Checking of objc_msgSend Calls 改为NO
id objc_msgSend(idself,SEL op, ...)
此方法为发送消息。第一个参数是接收参数,第二个是本类的方法--若是在本类找不到,他会按继承体系向上查找在MJRefresh的是这样填写参数的
objc_msgSend(self.beginRefreshingTaget,self.beginRefreshingAction,self);
5:加载倍图
UIImage imageWithContentsOfFile:<#(NSString *)#>
和 UIImage imageNamed:<#(NSString *)#>[UIImageimageNamed:@"image"];
此方法也可以加载倍图 @2x 的图片,//需要注意的是加载倍图的话,不可以在图片名字后加.png
<span style="font-size:18px;"> [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide]; statusHiden = YES; [self.navigationController setNavigationBarHidden:YES animated:YES]; [self setNeedsStatusBarAppearanceUpdate];//当没有nav的时候这句必不可少</span>
<span style="font-size:18px;">- (BOOL)prefersStatusBarHidden { return self.statusHiden;}</span>
7:
+ (NSArray *)constraintsWithVisualFormat:(NSString *)format options:(NSLayoutFormatOptions)opts metrics:(NSDictionary *)metrics views:(NSDictionary *)views;
@"V:|-80-[_imageView(80)]-[_label]"
V表示垂直_imageView(80)表示高度或者宽度是80
>=,<=,==表示值大于等于,小于等于或者等于@"|-(==80)-[_imageView(<=80)]"
@"V:|-[_imageView(_label)]"表示高度一样
第二个参数是格式
第三个参数为空。
第四个参数为NSDictionaryOfVariableBindings(_imageView, _label);
_imageView.translatesAutoresizingMaskIntoConstraints =NO;这个属性必须为NO
@"V:|-80-[_imageView(80)]-[_label(>=30@100)]"
label高度大于等于30最大值为100——@表示最大值——测试得@的功能没有什么用
8:空宏一般用于做条件编译
9:iOS8的自动旋转实现
<span style="font-size:18px;">- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) { UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; switch (orientation) { case UIInterfaceOrientationLandscapeLeft: NSLog(@"left"); break; case UIInterfaceOrientationLandscapeRight: NSLog(@"right"); break; case UIInterfaceOrientationPortrait: NSLog(@"portrait"); break; default: break; } } completion:^(id<UIViewControllerTransitionCoordinatorContext> context) { }]; [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];}</span>
10:加入第三方库或者使用svn的时候会造成文件大的难以想象
使用
cd到此文件夹
删除此文件夹下的所有.svn 和 .git 文件
find . -name ".git" | xargs rm -Rf
find . -name ".svn" | xargs rm -Rf
- iOS零碎小知识
- iOS零碎知识
- iOS开发零碎知识
- iOS零碎知识
- iOS 零碎知识笔记
- IOS开发:一些零碎知识
- 一些iOS开发中的零碎知识
- 涨姿势!iOS零碎知识小集
- 零碎知识
- 零碎知识
- 零碎知识
- 零碎知识
- 零碎知识。
- 零碎知识
- 零碎知识
- 零碎知识
- IOS学习笔记——一些零碎知识
- ios开发一些零碎的小知识(二)
- 我的权限系统设计实现MVC4 + WebAPI + EasyUI + Knockout(一)
- javax.servlet.jsp cannot be resolved to a type
- 即时音效
- java 多线程
- 1.14
- iOS零碎知识
- 第6周-初试“窗口”程序设计-VC++-MFCAPP工程
- Android多线程下载
- 我的权限系统设计实现MVC4 + WebAPI + EasyUI + Knockout(二)菜单导航
- Aerospike C客户端手册———Ubuntu 12 安装
- MyBatis的动态SQL详解
- Android Wifi密码查看器实现思路
- EditPlus如何实现自动换行
- 使用代理类增强业务类的功能示例