登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

vs-yanguo的博客

 
 
 

日志

 
 
 
 

iPhone 开发过程中的一些小技术的总结  

2010-10-25 19:01:40|  分类: objective c |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

1 随机数的使用
        头文件的引用
        #import <time.h>
        #import <mach/mach_time.h>
        srandom()的使用
        srandom((unsigned)(mach_absolute_time() & 0xFFFFFFFF));
         直接使用 random() 来调用随机数
2 在UIImageView 中旋转图像
        float rotateAngle = M_PI; 本文来自泠云天天在线
        CGAffineTransform transform =CGAffineTransformMakeRotation(rotateAngle);
        imageView.transform = transform;
      
         以上代码旋转imageView, 角度为rotateAngle, 方向可以自己测试哦!
3 在Quartz中如何设置旋转点
        UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];
        imageView.layer.anchorPoint = CGPointMake(0.5, 1.0);
        这个是把旋转点设置为底部中间。记住是在QuartzCore.framework中才得到支持。
4 创建.plist文件并存储
内容来自泠云天天在线
        NSString *errorDesc;  //用来存放错误信息
        NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:4]; //NSDictionary, NSData等文件可以直接转化为plist文件
        NSDictionary *innerDict;
        NSString *name;
        Player *player;
        NSInteger saveIndex;
    
        for(int i = 0; i < [playerArray count]; i++) {
              player = nil;
              player = [playerArray objectAtIndex:i];
              if(player == nil)
                     break;

lyttzx.com


              name = player.playerName;// This "Player1" denotes the player name could also be the computer name
              innerDict = [self getAllNodeInfoToDictionary:player];
              [rootObj setObject:innerDict forKey:name]; // This "Player1" denotes the person who start this game
        }
        player = nil;
        NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
        红色部分可以忽略,只是给rootObj添加一点内容。这个plistData为创建好的plist文件,用其writeToFile方法就可以写成文件。下面是代码: 泠云工作室
        
        /*得到移动设备上的文件存放位置*/
        NSString *documentsPath = [self getDocumentsDirectory];
        NSString *savePath = [documentsPath stringByAppendingPathComponent:@"save.plist"];
    
        /*存文件*/
        if (plistData) {
                [plistData writeToFile:savePath atomically:YES];
         }
         else {
                NSLog(errorDesc);
                [errorDesc release]; 内容来自泠云天天在线
        }
        - (NSString *)getDocumentsDirectory {  
                NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
                return [paths objectAtIndex:0];  
        }
4 读取plist文件并转化为NSDictionary
        NSString *documentsPath = [self getDocumentsDirectory];
        NSString *fullPath = [documentsPath stringByAppendingPathComponent:@"save.plist"]; 内容来自泠云天天在线
        NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPath];
5 读取一般性文档文件
        NSString *tmp;
        NSArray *lines; /*将文件转化为一行一行的*/
        lines = [[NSString    stringWithContentsOfFile:@"testFileReadLines.txt"]
                       componentsSeparatedByString:@"\n"];
    
         NSEnumerator *nse = [lines objectEnumerator];
    
         // 读取<>里的内容
本文来自泠云天天在线
         while(tmp = [nse nextObject]) {
                  NSString *stringBetweenBrackets = nil;
                  NSScanner *scanner = [NSScanner scannerWithString:tmp];
                  [scanner scanUpToString:@"<" intoString:nil];
                  [scanner scanString:@"<" intoString:nil];
                  [scanner scanUpToString:@">" intoString:&stringBetweenBrackets];
                  NSLog([stringBetweenBrackets description]);
内容来自泠云天天在线
          }
对于读写文件,还有补充,暂时到此。随机数和文件读写在游戏开发中经常用到。所以把部分内容放在这,以便和大家分享,也当记录,便于查找
  评论这张
 
阅读(176)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018