一、九宫格算法html
任意相似九宫格的算法,用for循环实现,在同一行的Y值相同,在同一列的X值相同,用求余和商来确认是同行仍是同列。ios
for (int i=0; i<(num); i++) { //同行的Y值相同,X变化 int col = i%colNum; CGFloat appViewX = (col + 1)*deltaX + col*appViewW; //同列的X值相同,Y变化 int row = i/colNum; CGFloat appViewY = startY + row*(appViewH + deltaY); UIView *appView = [[UIView alloc] initWithFrame:CGRectMake(appViewX, appViewY, appViewW, appViewH)]; // appView.backgroundColor = [UIColor yellowColor]; [self.view addSubview:appView]; }
二、字典转模型算法
错误提示:CUICatalog: Invalid asset name supplied: (null)数组
缘由是[UIImage imageNamed:nil];xcode
-(NSArray *)appList{ if(_appList == nil){ //applist保存的是字典=>模型 // NSString *p = [[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil]; NSArray *array = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil]]; // _appList = [NSArray arrayWithContentsOfFile:p]; //建立一个临时数组 NSMutableArray *arrM = [NSMutableArray array]; for (NSDictionary *dict in array) { AppleInfo *appInfo = [[AppleInfo alloc] init]; appInfo.name = dict[@"name"]; appInfo.icon = dict[@"icon"]; [arrM addObject:appInfo]; } _appList = arrM; } return _appList; }
/**
使用KVC的注意事项
1.plist中的键值名称必须与模型中的属性一致
2.模型中的属性能够不所有出如今plist中
*/网络
//KVC - key value coding(键值编码) //是一种间接修改/读取对象属性的一种方法 //KVC 被成为 cocoa 的大招 //参数: //1.数值 //2.属性名称 // [self setValue:dict[@"name"] forKey:@"name"]; // [self setValue:dict[@"icon"] forKey:@"icon"]; //setValuesForKeysWithDictionary本质上就是调用以上两句代码 [self setValuesForKeysWithDictionary:dict];
四、动画效果app
//*****给按键添加监听方法 [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
-(void)click:(UIButton *)button{ UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80, 480,160, 40)]; label.backgroundColor = [UIColor redColor]; label.text = [self.appList[button.tag] name]; label.textAlignment = NSTextAlignmentCenter; [self.view addSubview:label]; //初始透明度,彻底透明 label.alpha = 0.0; //******动画效果 [UIView animateWithDuration:1 animations:^{ label.alpha = 1; } completion:^(BOOL finished) { [UIView animateWithDuration:1 animations:^{ label.alpha = 0; } completion:^(BOOL finished) { [label removeFromSuperview]; }]; }]; }
五、重构iphone
原则:让代码放在最应该存在的地方ide
方法:动画
1)设定开发计划,开发步骤
2)每个步骤告一段落后,需哟啊暂停,审核代码,有针对性的重构
目前要作的,尽可能不要出现重复的代码!
六、XIB自定义文件
//*****使用XIB自定义视图,lastObject是数组最后一个 //使用XIB能够有多个控件,通常只使用一个 // AppView *appView = [[[NSBundle mainBundle] loadNibNamed:@"AppView" owner:nil options:nil] lastObject]; // AppView *appView = [AppView appView]; AppView *appView = [AppView appViewWithAppInfo:self.appList[i]]; appView.frame = CGRectMake(appViewX, appViewY, appViewW, appViewH); [self.view addSubview:appView]; //实现视图内部的细节 // AppleInfo *appInfo = self.appList[i]; appView.appleInfo = self.appList[i];
视频里不许确,http://www.th7.cn/Program/IOS/201507/496988.shtml
破解:
~/资源库/Caches/
com.ittybittyapps.Reveal文件删除
~/资源库/Preferences/
com.ittybittyapps.Reveal.plist删除
又可使用30天
Xcode6会有相似的功能
在Xcode中的使用方法:
一、首先安装好Reveal,下载地址:http://download.revealapp.com/Reveal.app.zip
二、在Reveal软件的菜单栏中选择【Help】-【Show Reveal Library In Finder】,会显示Reveal的FrameWork和dylib文件,须要在Xcode项目中引入。
三、在Xcode项目中配置以下几个地方:
1)添加Reveal的Framework文件,将Framework文件拖到项目导航面板中,在弹窗中选择Add to Target和Copy Item if need。(这个操做会把dylib文件复制到您的项目中,若是reveal更新了,那须要从新操做一遍来覆盖旧文件)
2)在项目配置区域,选择Build Phases,在Link Binary With Libraries节点中删除Reveal库。
3) 选择Build Setting,在右上角搜索框中输入关键字:Other Link,会自动帅选出Linking节点中的Other Linker Flags属性节点,输入内容:
-ObjC -lz -framework Reveal
三、Xcode的配置完成,如今选择一个iphone模拟器开始运行您的项目。运行成功后,切换到Reveal程序界面。在左上角No Connection那个下拉框中选择您的项目名称。
四、开始使用吧!Reveal的三维显示真的太棒了:
注意哦:若是您选择真机调试,那么须要确保手机和电脑处于同一个Wifi网络中(同一个网段中)。
我第一次使用时,就碰到这个问题:电脑插的有线链接的是不带无线功能的路由器(电脑网段是192.168.1.1),手机连的wifi是使用便携式wifi设备,网段是192.168.99.1,虽然2个设备都能联网,可是对于Reveal来讲,也许这样是没法识别到的,因此,我换了一个带无线的路由器,让手机和电脑的IP保持在一个网段内,就能够了!
tips:
本文由wp2osc导入,原文连接:http://devonios.com/ios-ui-reveal-in-xcode.html
因为OSChina的OpenAPI在处理content参数时会自动过滤img标签,因此没法显示图片,详见。