随笔分类 -  Objective-C

Quartz 2D绘图
摘要:Quartz 2D绘图只能在UIView中重写drawRect:方法中进行绘制,其他地方都无效,会报错。绘制过程:1. 获取上下文 CGContextRef context = UIGraphicsGetCurrentContext();2. 添加图形 CGContextAddRect(contex... 阅读全文

posted @ 2014-07-10 23:42 馅饼在哪颗星 阅读(364) 评论(0) 推荐(0)

手势识别
摘要:iOS目前支持的手势识别UITapGestureRecognizer(点按)UIPinchGestureRecognizer(捏合)UIPanGestureRecognizer(拖动)UISwipeGestureRecognizer(轻扫)UIRotationGestureRecognizer(旋转... 阅读全文

posted @ 2014-07-08 22:42 馅饼在哪颗星 阅读(232) 评论(0) 推荐(0)

多视图控制器跳转方法
摘要:1.Modal:打开:presentViewController关闭:dismissViewController2.Push:需搭配NavigationController使用,采用压栈和出栈的方式打开:pushViewController关闭:popViewController3.Segue:以上... 阅读全文

posted @ 2014-06-26 17:13 馅饼在哪颗星 阅读(301) 评论(0) 推荐(0)

NSString和NSDate的转换
摘要:输入的日期字符串形如:@"1992-05-21 13:08:08"- (NSDate*)dateFromString:(NSString*)dateString{NSDateFormatter*dateFormatter = [[NSDateFormatter alloc]init];[dateFo... 阅读全文

posted @ 2014-06-17 10:27 馅饼在哪颗星 阅读(221) 评论(0) 推荐(0)

遍历子视图中某个类型控件方法
摘要:NSMutableArray *textFieldArray = [NSMutableArray arrayWithCapacity:5]; for (UIView *textField in self.view.subviews) { if ([textFiel... 阅读全文

posted @ 2014-06-09 22:49 馅饼在哪颗星 阅读(219) 评论(0) 推荐(0)

发布程序后的NSLog批处理
摘要:NSLog在开发中是必须使用到的,但是其本身是特别耗费性能的,所以在产品发布后是一定要去掉的。在大的开发项目中一个个处理NSLog是相当困难的,所以可以考虑在pch文件中进行宏定义,如:#define MyLog(...) NSLog(__VA_ARGS__)待程序发布时可以将后面的NSLog(__... 阅读全文

posted @ 2014-06-06 11:14 馅饼在哪颗星 阅读(348) 评论(0) 推荐(0)

searchDisplayController用法
摘要:#pragma mark - 搜索栏代理方法- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchStrin... 阅读全文

posted @ 2014-06-02 17:40 馅饼在哪颗星 阅读(517) 评论(0) 推荐(0)

UIImagePickerController使用方法
摘要:点击按钮后弹出图片库选择图片,然后返回给Button的image。- (IBAction)selectIcon { UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init]; //设置图库源 ... 阅读全文

posted @ 2014-05-29 23:33 馅饼在哪颗星 阅读(358) 评论(0) 推荐(0)

沙盒目录常用获取方式
摘要:获取程序的Home目录 NSString *home = NSHomeDirectory();注意: 虚拟机Home目录: /Users/userName/Library/Application Support/iPhone Simulator/6.1/Applications/C926CCFA-A... 阅读全文

posted @ 2014-05-28 20:29 馅饼在哪颗星 阅读(299) 评论(0) 推荐(0)

Archive&Unarchive
摘要:Archive(归档)需要归档的对象必须要遵循NSCoding协议,那么在调用archiverRootObject方法的时候,会自动调用该对象的encodeWithCoder方法- (void)encodeWithCoder:(NSCoder *)aCoder{ [aCoder encodeO... 阅读全文

posted @ 2014-05-20 20:53 馅饼在哪颗星 阅读(365) 评论(0) 推荐(0)

UITableView随笔笔记
摘要:UITableView 继承自UIScrollView,所以可以滚动,但只能是纵方向上的。UITableView由section和cell组成,填充的内容来自数据源,一般数据源由ViewController作为代理,因此需要遵循它的两个协议,分别是UITableViewDataSource 和UIT... 阅读全文

posted @ 2014-05-14 19:16 馅饼在哪颗星 阅读(540) 评论(0) 推荐(1)

代理协议消息单方传递机制
摘要:单方消息传递通常用于子视图向主视图传递数据,步骤如下;1.在子视图中1.1 定义协议及协议中规定的方法,协议名通常是子视图控制器名+Delegate:@protocol GameViewControllerDelegate - (void)gameOverDeliverTimer:(NSString... 阅读全文

posted @ 2014-05-12 15:08 馅饼在哪颗星 阅读(247) 评论(0) 推荐(0)

NSTimer计时器随笔
摘要:实例化计时器:_timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];TimeInterval:以秒为单位... 阅读全文

posted @ 2014-05-12 14:48 馅饼在哪颗星 阅读(366) 评论(0) 推荐(0)

音乐和音效的加载播放
摘要:在有些应用中需要用到背景音乐和音效,那在程序中是这么实现的。1.首先加载背景音乐需要用到AVFoundation框架2.音乐资源都是在包里的,所以需要获得包路径,涉及方法- (id)initWithContentsOfURL:(NSURL *)url error:(NSError **)outErr... 阅读全文

posted @ 2014-05-09 16:56 馅饼在哪颗星 阅读(310) 评论(0) 推荐(1)

UIAlertView & UIActionSheet随笔笔记
摘要:系统UIAlertView在很多地方有使用到,其创建的初始化的方法为:- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /**/)delegate cancelButtonTitle:(NSS... 阅读全文

posted @ 2014-05-06 17:23 馅饼在哪颗星 阅读(261) 评论(0) 推荐(0)

UIView中的动画设置
摘要:两种状态的改变通过动画来渐变,设置动画效果,一般采用的方式有以下几种:方式一:[UIView beginAnimations:(NSString *) context:];[UIView setAnimationDuration:];/*****这里插入需要产生动画的片段*****/ [UIV... 阅读全文

posted @ 2014-04-29 22:02 馅饼在哪颗星 阅读(386) 评论(0) 推荐(0)

UIImage的两种加载方式
摘要:1.有缓存:读取后放入缓存中下次可直接读取,适用于图片较少且频繁使用。[UIImage imageNamed:@"文件名"];2.无缓存:用完就释放掉,参数传的是全路径,适用于图片较多的情况下。[UIImage alloc] initWithContentsOfFile:@"文件全路径"]; 阅读全文

posted @ 2014-04-29 10:08 馅饼在哪颗星 阅读(427) 评论(0) 推荐(0)

代码添加一个按钮及监听方法
摘要:有时候无法从控件中拖拽一个按钮到storyboard,必须用编写代码方式添加按钮: 1 - (void)viewDidLoad 2 { 3 [super viewDidLoad]; 4 // Do any additional setup after loading the view... 阅读全文

posted @ 2014-04-27 23:03 馅饼在哪颗星 阅读(314) 评论(0) 推荐(0)

NSBundle 读取资源包中的文件
摘要:访问项目中资源包里面所有资源使用方法。读取资源包descs.plist文件方法如下:NSBundle *bundle = [NSBundle mainBundle]; //创建bundle对象NSString *path = [bundle pathForResourc... 阅读全文

posted @ 2014-04-27 22:24 馅饼在哪颗星 阅读(371) 评论(0) 推荐(0)

导航