好久沒更新博客了,一方面是.......另外一方面是項目忙數組
迴歸正題,將近兩年的開發過程當中,我都會把學習到的一些東西記錄下來,工具用的是印象筆記,這確實是個不錯的學習方法。不過印象筆記並不支持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; }