机器猫工作笔记(持续更新中...)
1.如何手动停止CAKeyframeAnimation的动画
//暂停动画 -(void)pauseLayer:(CALayer*)layer { CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil]; layer.speed = 0.0; layer.timeOffset = pausedTime; }
2.有时候不能用无线去验证,把无线关掉就好
3.二维码扫描中扫描区域的大小设置
CGRect intertRect = [previewLayer metadataOutputRectOfInterestForRect:rect]; CGRect layerRect = [previewLayer rectForMetadataOutputRectOfInterest:intertRect]; //相互转换两种frame的相互转换(二维码有效区域frame是不一样的)
4.Xcode7.2找不到头文件
按照这个解决了http://stackoverflow.com/questions/10714600/cdvplugin-h-file-not-found-in-cordova-as-component-cleaver里面写着Forxcode7 add "$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include" to your Header Search Paths and set Enable Bitcode to No 我这里确实解决了,希望能帮到你们.
NSMutableString *newtxt = [NSMutableString stringWithString:textField.text]; [newtxt replaceCharactersInRange:range withString:string];
6.头文件找不到问题
For xcode7 add "$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include" to your Header Search Paths and set Enable Bitcode to No
7.Tableview不识别touchesBegan方法
UITableView是不会响应touchesBegan:withEvent:之类的UIResponder的方法的。因此,加在其上的所有视图的响应者链就断了。如果在UITableView其上加任何的自身不具备类似UIButton一样有目标动作机制的UIView及其子类控件的时候,这个控件也不会响应touchesBegan:withEvent:方法。即便是设置该控件的userInteractionEnabled为YES也没用。
如此一来,如果想要这些控件具有交互性能怎么办?有一种很直观的方法,给这个控件加上手势识别器。
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesturedDetected:)]; // 手势类型随你喜欢。 tapGesture.delegate = self; [yourView addGestureRecognizer:panGesture];
// do something
8.tabBar角标(徽章应用)
[[self.tabBar.items objectAtIndex:1] setBadgeValue:@"10"];
// 向操作系统申请后台运行的资格,能维持多久,是不确定的 UIBackgroundTaskIdentifier task = [application beginBackgroundTaskWithExpirationHandler:^{ // 当申请的后台运行时间已经结束(过期),就会调用这个block // 过期则需要结束任务 [application endBackgroundTask:task]; }];
NSString *str = @"我擦"; NSString *body = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSLog(@"%@",body);
11.字典转json格式字符串
NSError *parseError = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError]; return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
12.CocoaPods中的头文件import导入时不能自动补齐的解决方法
点击按钮,将self.imageView上面的image内容保存到本地相册,并指定判断保存成功与否的方法imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:
UIImageWriteToSavedPhotosAlbum(self.imageView.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
实现imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:方法
NSString *message = @"呵呵"; if (!error) { message = @"成功保存到相册"; }else { message = [error description]; } NSLog(@"message is %@",message);
16.Xcode 7.1上传
1.https://developer.apple.com/certificationauthority/AppleWWDRCA.cer下载最新AppleWWDRCA证书,双击安装。
2.打开钥匙串,选择登录,然后选择下面的证书。
3.选择桌面左上角的显示→显示已过期的证书。
4.这时候你会发现一个过期的“WWDR Certificate”(Apple Worldwide Developer Relations Certification Authority),删除它。
特别注意:有的在系统那一栏也有这个过期的“WWDR Certificate”,也一并删除它,没有就不作处理。
首先检查了SDWebImage代码中对于memory warning的处理:
[self.memCache removeAllObjects];
[[SDImageCache sharedImageCache] setValue:nil forKey:@"memCache"];
可解决。
NSNumberFormatter *formatter = [[NSNumberFormatter alloc]init]; formatter.numberStyle =kCFNumberFormatterCurrencyStyle; NSString *newAmount = [[formatter stringFromNumber:[NSNumber numberWithInt:[dic[@"amount"] intValue]]] substringFromIndex:1];
__weak typeof(self) VC = self;
23.模态界面的直接返回父视图的根视图
self.presentingViewController.view.alpha = 0; [self.presentingViewController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
24.NSUserDefaults 存取
[[NSUserDefaults standardUserDefaults] setBool:@YESforKey:loginStr]; [[NSUserDefaults standardUserDefaults] synchronize]; NSUserDefaults *UD = [NSUserDefaults standardUserDefaults]; BOOL login = [UD objectForKey:loginStr];
25.配置path
library path-- $(SRCROOT)/ *** framework path-- $(PROJECT_DIR)/*** $(inherited)
26.解决分割线缺失一段
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparatorInset:UIEdgeInsetsZero]; } if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { [self.tableView setLayoutMargins:UIEdgeInsetsZero]; }
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setSeparatorInset:)]){ [cell setSeparatorInset:UIEdgeInsetsZero]; }
dispatch_async(dispatch_get_global_queue(0, 0), ^{ NSTimer *t = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(configureTimerr:) userInfo:@{@"strTime":strTime,@"endTime":endTime} repeats:YES]; [[NSRunLoop currentRunLoop] addTimer:t forMode:NSDefaultRunLoopMode]; [[NSRunLoop currentRunLoop] run]; });
30.init里边初始controller.注册通知.通知无效(通知的结果操作view,还没调用load view,view为nil)
31.防止用户多次点击按钮弹窗重复
@synchronized(self){ if (self.view.userInteractionEnabled == NO) return; } self.view.userInteractionEnabled = NO; //防止用户多次点击按钮弹窗重复
static dispatch_once_t predicate; dispatch_once(&predicate, ^{ sharedAccountManagerInstance = [self alloc] init]; });
35.判断是否有自定义键盘,自定义键盘和第三方键盘的class不一样
NSArray *array = [UITextInputMode activeInputModes];//获取键盘类型个数 if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0) { //系统大于9.0的时候,在系统键盘上多了一层layer层可修改 temp = [[[UIApplication sharedApplication] windows] objectAtIndex:2]; }else { //系统不大于9.0时候,在系统键盘上没有那一层 temp = [[[UIApplication sharedApplication] windows] objectAtIndex:1]; } [temp addSubview:_dianBT];
[[metadataobj stringValue] rangeOfString:@"FGM"].location !=NSNotFound
37. [UIScreen mainScreen].bounds.size.width值不改变问题
在LaunchImage中必须有Default.png和Default-568h.png文件,如果iOS 检测不到这两个文件就不会根据屏幕尺寸适配
38.解决在tableview和collection view中的手势冲突问题
DLog(@"1"); if ([touch.view isKindOfClass:[UITextField class]]) { return NO; } // 若为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件 if ([NSStringFromClass([touch.view class])isEqualToString:@"UITableViewCellContentView"]) { return YES; } return YES;
39.版本控制示例
#if __IPHONE_OS_VERSION_MAX_ALLOWED < __IPHONE_9_0 - (NSUInteger)supportedInterfaceOrientations #else - (UIInterfaceOrientationMask)supportedInterfaceOrientations #endif { return UIInterfaceOrientationMaskLandscape; }
40.搜索关键词高亮
//搜索关键字高亮 NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:model.name]; NSRange range = [model.name rangeOfString:_mySearch.text]; [attr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range]; cell.titleLabel.attributedText = attr;
[_mapview showAnnotations:@[_annotation] animated:NO];
会自动把视角移动到这几个标记点上.坑
以下几个是比较常用的几个点:
//当前屏幕中心点的经纬度 CGFloat centerLongitude = self.mapView.region.center.longitude; CGFloat centerLatitude = self.mapView.region.center.latitude; //当前屏幕显示范围的经纬度 CLLocationDegrees pointssLongitudeDelta = self.mapView.region.span.longitudeDelta; CLLocationDegrees pointssLatitudeDelta = self.mapView.region.span.latitudeDelta; //左上角 CGFloat leftUpLong = centerLongitude - pointssLongitudeDelta/2.0; CGFloat leftUpLati = centerLatitude - pointssLatitudeDelta/2.0; //右上角 CGFloat rightUpLong = centerLongitude + pointssLongitudeDelta/2.0; CGFloat rightUpLati = centerLatitude - pointssLatitudeDelta/2.0; //左下角 CGFloat leftDownLong = centerLongitude - pointssLongitudeDelta/2.0; CGFloat leftDownlati = centerLatitude + pointssLatitudeDelta/2.0; //右下角 CGFloat rightDownLong = centerLongitude + pointssLongitudeDelta/2.0; CGFloat rightDownLati = centerLatitude + pointssLatitudeDelta/2.0; NSLog(@"\n 左上 %f,%f---------\n 右上 %f,%f-------\n 左下 %f,%f----- \n 右下 %f,%f",leftUpLong,leftUpLati,rightUpLong,rightUpLati,leftDownLong,leftDownlati,rightDownLong,rightDownLati);
持续更新中....有错误的地方请大神指教,不胜感激.