IOS 初级第二星期 总结.docx
- 文档编号:5981014
- 上传时间:2023-05-09
- 格式:DOCX
- 页数:18
- 大小:543.90KB
IOS 初级第二星期 总结.docx
《IOS 初级第二星期 总结.docx》由会员分享,可在线阅读,更多相关《IOS 初级第二星期 总结.docx(18页珍藏版)》请在冰点文库上搜索。
IOS初级第二星期总结
第二星期总结
第七天整理
(如果不小心删除xib文件创建的方法定时器的建立以及使用例子‘雪花下落’有关随机变量静态数组动态数组静态字典动态字典)
(拥有者的类型为UIView)
//1.不停的下落
//NSTimer定时器
//scheduled日程安排
//Interval间隔单位是s
//target目标self
//selector方法名
//userInfo用户信息
//repeats重复
NSTimer*timer=[NSTimerscheduledTimerWithTimeInterval:
10target:
selfselector:
@selector(onTimer)userInfo:
nilrepeats:
YES];
//不会等待第一个间隔直接执行定时器方法
[timerfire];
//invalidate让定时器失效
//[timerinvalidate];
//2.创建雪花图片视图的对象,位置是随机的
//arc4random()随机数
//0-320
inti=arc4random()%321;
//取余如果对n取余等到范围是0-(n-1)
//动画结束后选择的方法
[UIViewsetAnimationDidStopSelector:
@selector(animationDidStop:
finished:
context:
)];
//NSArray数组
//NSDictionary字典
//数组用来存放对象的
NSArray*array=[[NSArrayalloc]initWithObjects:
@"1",@"2",@"3",nil];
//count计数用来输出数组的个数
NSLog(@"===%d",array.count);
//获取数组中的对象objectAtIndex
//objectAtIndex对象在索引:
//索引值从0开始
NSString*str=[arrayobjectAtIndex:
2];
NSLog(@"=====%@",str);
//reason:
'***-[__NSArrayIobjectAtIndex:
]:
index3beyondbounds[0..2]'此处错误是超出了数组定义的范围
//遍历
//for循环
for(inti=0;i { NSString*string=[arrayobjectAtIndex: i]; NSLog(@"string=%@",string); } //forin遍历 for(NSString*stringinarray) { NSLog(@"==string=%@",string); } //Mutable可变的 //Capacity容量 NSMutableArray*mutableArray=[[NSMutableArrayalloc]initWithCapacity: 0]; for(inti=1;i<6;i++) { //Format格式 //拼接字符串格式化字符串 NSString*string=[NSStringstringWithFormat: @"%d",i]; NSLog(@"====string==%@",string); //addObject往数组中添加对象 [mutableArrayaddObject: string]; } //通过索引来移除对象 [mutableArrayremoveObjectAtIndex: 4]; //往数组中插入数据 //[mutableArrayinsertObject: @"20"atIndex: 2]; //replace替换 //[mutableArrayreplaceObjectAtIndex: <#(NSUInteger)#>withObject: <#(id)#>]; //字典无顺序的 //数组是有顺序的 //一个对象可有多个key,一个key只能对应一个对象 NSDictionary*dic=[[NSDictionaryalloc]initWithObjectsAndKeys: @"宝马",@"car",@"范冰冰",@"美女",nil]; //通过key来获取值 //objectForKey NSString*car=[dicobjectForKey: @"car"]; NSLog(@"======%@",car); //找到所有的key NSArray*dicArray=[dicallKeys]; for(NSString*stringindicArray){ NSLog(@"%@",string); } //NSLog(@"%@",dicArray); //找到所有的key对应的值 NSArray*heroTell=[dicallValues]; for(NSString*stringinheroTell){ NSLog(@"%@",string); //动态可删减的字典 NSMutableDictionary*mutableDic=[[NSMutableDictionaryalloc]initWithCapacity: 4]; [mutableDicsetObject: @"还有谁"forKey: @"贾克斯"]; NSArray*heroTell2=[mutableDicallValues]; for(NSString*stringinheroTell2){ NSLog(@"%@",string); } NSString*string=[mutableDicobjectForKey: @"贾克斯"]; NSLog(@"%@",string); 第八天 (雪花下落用数组Array来做为了使查找的时间更长定义静态count获得手机屏幕中鼠标的位置) //定义静态count用来使查找雪花的时间更长 staticintcount=0; -(void)onTime { count++; if(count==10){ //找雪花 [selffindSnow]; //让count值++,当等于10的时候找一次雪花 //定时器不断的执行count值会大于10,就再也找不到雪花了,所以要把count值重新归0 count=0; } [selfsnowDown]; } if(imageView.isUse==YES) { //记住记住CGRect的用法 CGRectrect=imageView.frame; rect.origin.y+=10; //y改变后要重新赋值 imageView.frame=rect; //如果雪花出了屏幕以后,让isuse属性变为no以便于重用 if(rect.origin.y>=480) { imageView.isUse=NO; } //toucher所有触摸点得集合 -(void)touchesMoved: (NSSet*)toucheswithEvent: (UIEvent*)event { //只要点击屏幕就可以触发事件关键是那个飞机是怎么移动的在这里设置飞机移动 //获得每一个touch对象 UITouch*touchtag=[touchesanyObject]; //每一个触摸点的xy坐标 CGPointpiont=[touchtaglocationInView: self.view]; //planeButton.center=piont; planeIV.center=piont; } 第九天 (打灰机系列给文件添加声音怎样判断子弹跟敌机相交以及相交所做的处理帧动画的制作) //Bundle束应用程序的目录 NSBundle*bundle=[NSBundlemainBundle]; //获取资源文件的路径 NSString*path=[bundlepathForResource: @"想你的夜"ofType: @"mp3"]; NSLog(@"=====%@",path); // NSURL*url=[[NSURLalloc]initFileURLWithPath: path]; // player=[[AVPlayeralloc]initWithURL: url]; [playerplay]; 获得屏幕内子弹的坐标 CGRectbulletRect=bulletImage.frame; //Intersect相交 if(CGRectIntersectsRect(enemyRect,bulletRect)) { NSLog(@"💥我的小宇宙"); UIImageView*boomImageView=[[UIImageViewalloc]initWithFrame: enemyRect]; //boomImageView.image=[UIImageimageNamed: @"DJBob1"]; [self.viewaddSubview: boomImageView]; //帧动画 boomImageView.animationImages=array; //设置一个循环的持续时间 boomImageView.animationDuration=0.5; //设置重复的次数 boomImageView.animationRepeatCount=0; [boomImageViewstartAnimating]; //延迟多少s执行的方法目的是执行移除爆炸图片的方法 [selfperformSelector: @selector(remove: )withObject: boomImageViewafterDelay: 1]; //下面是我自己做到这里时整理的 //找到后准备就绪发射子弹完成发射子弹的方法 -(void)fireBullet { for(bulletIVinbulletArray) { if(bulletIV.isUse==YES) { CGRectrect=bulletIV.frame; rect.origin.y-=20; if(rect.origin.y<=-10) { //这种更改imageView的方法有缺点下面有解释建议更改坐标同样能达到效果 bulletIV.isUse=NO; //bulletIV.frame=CGRectMake(0,-450,5,10); } bulletIV.frame=rect; [selfcrash: rect]; } } } //写当子弹和敌机相撞时所发生的爆炸事件 -(void)crash: (CGRect)bulletRect { for(enemyPlaneIVinenemyPlaneArray) { if(enemyPlaneIV.isUse==YES) { CGRectenemyRect=enemyPlaneIV.frame; if(CGRectIntersectsRect(bulletRect,enemyRect)) { UIImageView*bobIV=[[UIImageViewalloc]initWithFrame: enemyRect]; [self.viewaddSubview: bobIV]; [bobIVsetAnimationImages: bobArray]; [bobIVsetAnimationDuration: 1]; [bobIVsetAnimationRepeatCount: 0]; [bobIVstartAnimating]; [selfperformSelector: @selector(removeBob: )withObject: bobIVafterDelay: 1]; //如果使用以下这种方法飞机很容易在屏幕总卡住所以不建议使用而是建议使用更改坐标的方法 //enemyPlaneIV.isUse=NO; //bulletIV.isUse=NO; enemyPlaneIV.frame=CGRectMake(0,490,20,20); bulletIV.frame=CGRectMake(0,-450,5,10); score+=100; markLabel.text=[NSStringstringWithFormat: @"%d",score]; } } } } //实现移除爆炸效果的方法 -(void)removeBob: (UIImageView*)moveImageView { [moveImageViewremoveFromSuperview]; } 第十天 (利用定时器来完成帧动画杜老大介绍了两种方法以及第一次考试最后一道题平均分布九个按钮) 第一种比较简单就是利用定时器来完成图片的切换//1.创建视图对象 imageView=[[UIImageViewalloc]initWithFrame: self.view.frame]; imageView.image=[UIImageimageNamed: @"campFire01.gif"]; [self.viewaddSubview: imageView]; //开启定时器 [NSTimerscheduledTimerWithTimeInterval: 0.2target: selfselector: @selector(onTimer)userInfo: nilrepeats: YES]; } staticinti=0; -(void)onTimer { i++; imageView.image=[UIImageimageNamed: [NSStringstringWithFormat: @"campFire%02d.gif",i]]; if(i==17){ i=0; } } 第二种方法创建数组然后再定时器中遍历数组 //1.创建视图对象 imageView=[[UIImageViewalloc]initWithFrame: self.view.frame]; imageView.image=[UIImageimageNamed: @"campFire01.gif"]; [self.viewaddSubview: imageView]; array=[[NSMutableArrayalloc]initWithCapacity: 0]; for(inti=1;i<18;i++) { UIImage*image=[UIImageimageNamed: [NSStringstringWithFormat: @"campFire%02d.gif",i]]; [arrayaddObject: image]; } //开启定时器 [NSTimerscheduledTimerWithTimeInterval: 0.2target: selfselector: @selector(onTimer)userInfo: nilrepeats: YES]; } staticinti=0; -(void)onTimer { imageView.image=[arrayobjectAtIndex: i]; i++; if(i>=17) { i=i%17; } } 九宫格 //获取每个间隔的大小 floatxInterval=(320-3*50)/4; floatyInterval=(480-3*50)/4; for(inti=0;i<9;i++) { UIButton*btn=[UIButtonbuttonWithType: UIButtonTypeCustom]; //012345678 //对3取余i%3 //012012012 //对3取整i/3 //000111222 //考虑间隔+组合的个数 floatx=xInterval+i%3*(xInterval+50); floaty=yInterval+i/3*(yInterval+50); btn.frame=CGRectMake(x,y,50,50); btn.backgroundColor=[UIColoryellowColor]; [self.viewaddSubview: btn]; } 第十一天 (获得屏幕上的所有子视图 有关AlertView以及ActionSheet的设定以及导航控制器的初步讲解Navigation以及用自己的设定的alertView的初步讲解) //alert警告 UIAlertView*alertView=[[UIAlertViewalloc]initWithTitle: @"温馨提示"message: @"改变背景颜色"delegate: selfcancelButtonTitle: @"cancel"otherButtonTitles: @"changeColor",nil]; alertView.tag=10010; //show展示 [alertViewshow]; //传递当前类对象做为代理就可以去使用系统的协议方法或者代理方法 //两个参数1.用来区分对象2.区分按钮 //协议方法 -(void)alertView: (UIAlertView*)alertViewclickedButtonAtIndex: (NSInteger)buttonIndex { //改变颜色 if(alertView.tag==10010) { if(buttonIndex==1) { self.view.backgroundColor=[UIColoryellowColor]; } } //改变透明度 if(alertView.tag==10086){ if(buttonIndex==1){ self.view.alpha=0.5; } } NSLog(@"buttonindex=%d",buttonIndex); } //获得屏幕上的所有子视图 array=[self.viewsubviews]; //destructive破坏 UIActionSheet*actionSheet=[[UIActionSheetalloc]initWithTitle: @"ActionSheet"delegate: selfcancelButtonTitle: @"cancel"destructiveButtonTitle: @"destructive"otherButtonTitles: @"ok",nil]; [actionSheetshowInView: self.view]; //协议方法 -(void)actionSheet: (UIActionSheet*)actionSheetclickedButtonAtIndex: (NSInteger)buttonIndex { if(buttonIndex==0) { //遍历所有的子视图 for(UIView*viewinarray) { //判断对象是否为UITextField的类型 if([viewisKindOfClass: [UITextFieldclass]]) { [viewremoveFromSuperview]; } } } } //容器类 //导航控制器 //Navigation导航海航 FirstViewController*firstVC=[[FirstViewControlleralloc]init]; //initWithRootViewController设置根视图控制器 //创建导航控制器的对象 //并且设置根视图控制器 UINavigationController*nav=[[UINavigationControlleralloc]initWithRootViewController: firstVC]; //把导航控制器的对象添加到window上 self.window.rootViewController=nav; SecondViewController*secVC=[[SecondViewControlleralloc]init]; //self.navigationController获取当前视图控制器所在的导航控制器 //push压栈 //栈的数据结构的原则是先进后出,后进先出 [self.navigationControllerpushViewController: secVCanimated: YES]; //出栈 [self.navigationControllerpopViewControllerAnimated: YES]; //创建了barbutton的对象 UIBarButtonItem*leftBtn=[[UIBarButtonItemalloc]initWithTitle: @"goback"style: UIBarButtonItemStyleDonetarget: selfaction: @selector(goback)]; UIBarButtonItem*rightBtn=[[UIBarButtonItemalloc]initWithBarButtonSystemItem
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- IOS 初级第二星期 总结 初级 第二 星期