好久没更新博客了,一方面是.......另外一方面是项目忙数组
回归正题,将近两年的开发过程当中,我都会把学习到的一些东西记录下来,工具用的是印象笔记,这确实是个不错的学习方法。不过印象笔记并不支持markdown,网上也有不少方法让笔记以markdown语法的格式保存到印象笔记中。目前我用的是马克飞象这款工具,比较方便,专业版是收费的。markdown
下面是我两年来一些无分类的琐碎笔记,或许有些对你们有帮助app
NSArray *array=[[NSArray alloc]initWithObjects:@"苹果",@"香蕉",@"草莓", @"菠萝", nil]; NSString *newString=[array componentsJoinedByString:@","]; NSLog(@"%@", newString);
2013-10-29 15:38:23.372 Nurse[4001:c07] 苹果,香蕉,草莓,菠萝
_工具
- (void)viewDidLoad { NSString *a = [[NSString alloc] initWithString : @"冬瓜,西瓜,火龙果,大头,小狗" ]; NSArray *b = [a componentsSeparatedByString:@","]; }
_性能
CGFloat R, G, B; const CGFloat *components = CGColorGetComponents(color.CGColor); R = components[0]; G = components[1]; B = components[2];
_学习
有些时候图片旋转后会存在一些比较严重的锯齿效果url
解决办法:在项目plist文件中添加名为UIViewEdgeAntialiasing的key
并设置为YES
,可是这样可能会对性能产生严重的影响。
Apple的解释:Use antialiasing when drawing a layer that is not aligned to pixel boundaries. This option allows for more sophisticated rendering in the simulator but can have a noticeable impact on performance.code
简单办法:原始图片的四周作一个1像素的透明
_component
iOS 7以后orm
UIGraphicsBeginImageContextWithOptions(_sourceViewController.view.frame.size, YES, 0.0); [self.sourceViewController.view.window drawViewHierarchyInRect:_sourceViewController.view.frame afterScreenUpdates:NO]; UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
__
在VC中重写
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
方法
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [super touchesBegan:touches withEvent:event]; [self.view endEditing:YES]; }
_
若是在包含UITableView视图中添加单击手势,这个单击手势会屏蔽掉UITableView的
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
能够利用UIGestureRecognizer
的Delegate
中的
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer;
在单击点位于UITableView内的时候取消响应
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ CGPoint point = [gestureRecognizer locationInView:self]; if(CGRectContainsPoint(menuTableView.frame, point)){ return NO; } return YES; }
简单点的就将单击手势的cancelsTouchesInView设置为NO便可
singleTap.cancelsTouchesInView = NO;
_
解决办法
NSString *tempString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL URLWithString:tempString];
_
unichar c = [searchString characterAtIndex:0]; // 汉字 if (c >= 0x4E00 && c <= 0x9FFF){ } // 英文 else{ }
_
#define tranformDegree(x) ((x)*(M_PI)/(180.0f))
弧度 = 角度* π / 180
_
经过在cell中的子视图,例子中是button
NSIndexPath *path = [_collectionView indexPathForItemAtPoint:[button convertPoint:CGPointZero toView:self.collectionView]];
适用于UITableView(API不一样)和UICollectionView
_
- (BOOL)isDescendantOfView:(UIView *)view;
_
#if __LP64__ #define NSI "ld" #define NSU "lu" #else #define NSI "d" #define NSU "u" #endif
使用
NSInteger row = 2; NSLog(@"i=%"NSI, row);
_
NSLog(@"%@", @"a" ?: @"b"); // @"a"
若是成立返回?
语法的消息接收者,这里就是@"a"。经常使用:
cell.titleLabel.text = self.name ?:nil;
_
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
_
跳转到产品详情界面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"itms-apps://itunes.apple.com/app/idxxxxxx"]];
跳转到产品评论界面
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=xxxxxx&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"]];
xxxxx是的Apple ID
_
self.tableView.contentOffset = CGPointMake(0, 0 - self.tableView.contentInset.top);
_
在AppDelegate中添加
- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier { if ([extensionPointIdentifier isEqualToString: UIApplicationKeyboardExtensionPointIdentifier]) { return NO; } return YES; }