iOS零零碎碎备忘录
Updated:
- 1. iOS零零碎碎备忘录
- 1.1. 1.CGRectInset
- 1.2. 2.注释
- 1.3. 3.@import写法(Modules)
- 1.4. 4.删除线
- 1.5. 5.修改图片颜色
- 1.6. 6.Objc与C/C++混编注意
- 1.7. 7.一个ARC中引用申明的错误
- 1.8. 8.iOS8 NSUserDefaults模拟器中的清除
- 1.9. 9.获取中文拼音CFStringTransform
- 1.10. 10.GCD定时器
- 1.11. 11.解决xcode6模拟器启动Bug
- 1.12. 12.ios7滑动返回手势 及是否取消判断interactivePopGestureRecognizer
- 1.13. 13.设置空间全局颜色appearance proxy
- 1.14. 14.autolayout scrollview刺头
- 1.15. 15.storyboard详解
- 1.16. 16.基于cocospod创建静态库
- 1.17. 17.ios8适配
- 1.18. 18.崩溃信息收集
- 1.19. 19.@compatibility_alias
iOS零零碎碎备忘录
1.CGRectInset
CGRect CGRectInset(
CGRect rect,
CGFloat dx,
CGFloat dy)
该结构体可以表示已rect为中心,结合dx,dy形成的一个矩形CGRect区域
2.注释
这样格式的注释 调用时将被自动加入到提示中
附javadoc http://en.wikipedia.org/wiki/Javadoc
3.@import写法(Modules)
@import MessageUI; 等价于 #import
@import MessageUI.MFMailComposeViewController; 等价于 #import
如果使用的是iOS7或者MacOS10.9的SDK,在Build Settings中将Enable Modules(C and Objective-C)打开,然后保持原来的#import写法就行了。是的,不需要任何代码上的改变,编译器会在编译的时候自动地把可能的地方换成Modules的写法去编译的。
4.删除线
删除线 可以用attribute NSStrikethroughStyleAttributeName,再也不用自己画了
5.修改图片颜色
- (void)drawInRect:(CGRect)rect blendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha
;修改图片颜色
6.Objc与C/C++混编注意
在做混合编译之前一定要把编译器的Compile Sources As选项改为Objective C++。
7.一个ARC中引用申明的错误
Receiver type ‘X’ for instance message is a forward declaration
这往往是引用的问题。ARC要求完整的前向引用,也就是说在MRC时代可能只需要在.h中申明@class就可以,但是在ARC中如果调用某个子类中未覆盖的父类中的方法的话,必须对父类.h引用,否则无法编译。
8.iOS8 NSUserDefaults模拟器中的清除
Macintosh HD ▸ Users ▸ username ▸ Library ▸ Developer ▸ CoreSimulator ▸ Devices ▸ SIMULATORUUID ▸ data ▸ Library ▸ Preferences ▸ YourApplicationBundleID.plist
删除这个路径下的plist就可以清除了。
9.获取中文拼音CFStringTransform
例子
`
- (NSString)getSpellForWord:(NSString)word
{
NSMutableString spell = [NSMutableString stringWithString:word];
CFRange range = CFRangeMake(0, spell.length);
CFStringTransform((CFMutableStringRef)spell, &range, kCFStringTransformMandarinLatin, NO);
CFStringTransform((CFMutableStringRef)spell, &range, kCFStringTransformStripCombiningMarks, NO);
spell = (NSMutableString)[spell trim];
return spell;
}`
10.GCD定时器
__block int timeout = 2; //倒计时时间
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(self.timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
dispatch_source_set_event_handler(self.timer, ^{
if(timeout<=0){
dispatch_source_cancel(self.timer);
dispatch_async(dispatch_get_main_queue(), ^{
//设置界面的按钮显示 根据自己需求设置
[self hiddenView];
});
}else{
timeout--;
}
});
dispatch_resume(self.timer);
11.解决xcode6模拟器启动Bug
- Open the simulator via Xcode -> Open Developer Tool -> iOS simulator (even if it can’t launch, the app will be open).
- With the simulator app open, go to Hardware -> Device -> Manage Devices.
- Add any missing simulators with the plus button (all of mine were missing for some reason).
12.ios7滑动返回手势 及是否取消判断interactivePopGestureRecognizer
`
- (void)navigationController:(UINavigationController )navigationController willShowViewController:(UIViewController )viewController animated:(BOOL)animated
{
}];id<UIViewControllerTransitionCoordinator]] tc = navigationController.topViewController.transitionCoordinator; [tc notifyWhenInteractionEndsUsingBlock:^(id<UIViewControllerTransitionCoordinatorContext]] context) { NSLog(@"7: %i", [context isCancelled]);
}`
13.设置空间全局颜色appearance proxy
http://blog.csdn.net/huifeidexin_1/article/details/11890119
14.autolayout scrollview刺头
http://andyyou.logdown.com/posts/218193-ios-use-uiscrollview-autolayout
http://blog.csdn.net/meegomeego/article/details/39995477
15.storyboard详解
http://www.cocoachina.com/ios/20141124/10301.html
16.基于cocospod创建静态库
http://www.cnblogs.com/brycezhang/p/4117180.html
17.ios8适配
Launch Screen.xib 只能在iOS7.1,低于该版本需要提供两套启动图
http://www.jianshu.com/p/22ec8d179d2e
18.崩溃信息收集
UncaughtExceptionHandler
19.@compatibility_alias
给类一个别名