`
niCe
  • 浏览: 40512 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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

阅读更多

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;
              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]);
          }


对于读写文件,还有补充,暂时到此。随机数和文件读写在游戏开发中经常用到。所以把部分内容放在这,以便和大家分享,也当记录,便于查找。

6 隐藏NavigationBar
[self.navigationController setNavigationBarHidden:YES animated:YES];

在想隐藏的ViewController中使用就可以了。

分享到:
评论

相关推荐

    如何学习iPhone之开发过程中的一些小技术的总结--千锋培训

    文档介绍了1 随机数的使用,2 在UIImageView 中旋转图像,3 在Quartz中如何设置旋转点,4 创建.plist文件并存储,5 读取plist文件并转化为NSDictionary,6 读取一般性文档文件,7隐藏NavigationBar

    iphone开发中的一些小技巧

    iphone开发中的一些小技巧(包含代码)

    iPhone开发基础教程电子书

    给大家推荐一下,上面有斯坦福大学iphone开发视频教程中英文字幕版1-6集,还有超过100本的iphone开发方面的电子书可下载(速度很快哦!)。  更新:如果大家在学习和工作中遇到什么问题,请给我留言,大家...

    iPhone开发实战.pdf

    iPhone开发实战 iPhone开发 iPhone iPhone4 iPhone开发实战 iPhone开发 iPhone iPhone4

    iphone创意开发入门与实践总结

    iphone创意开发入门与实践总结

    Iphone开发系列源码——Iphone主题源码

    Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码...

    轻松学iPhone开发

    轻松学iPhone共分3篇。第1篇介绍iPhone的发展、iPhone开发环境以及开发工具的安装过程、iPhone Simulator模拟器

    《iPhone App开发实战手册》中文高清版

    本书将向你展示完整的开发过程,从下载工具,开发应用,进行测试,通过苹果的审核,到推销和维护你的产品。本书适合iPhone App开发入门使用。无论是开发人员、设计师、市场人员,还是项目经理,都可以在本书中找到...

    Iphone开发系列源码——iPhone版Wordpress源代码

    Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码...

    iPhone开发基础教程

    《iPhone开发基础教程》内容完整丰富,具有较强的通用性,编程领域中各层次读者都能通过《iPhone开发基础教程》快速学习iPhone开发,提高相关技能。iPhone 是一种全新的移动平台,苹果公司为它推出了强大的软件开发...

    iPhone开发入门到精通视频教程

    资源名称:iPhone开发入门到精通视频教程资源目录:【】iOS开发源码系列---工具【】iOS开发源码系列---应用【】iOS开发源码系列---游戏【】iOS开发源码系列---类库与框架【】iOS开发真机测试与发布【】iOS开发视频...

    iPhone游戏开发

    iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发iPhone游戏开发

    iPhone开发基础教程-PDF版

    iPhone开发,iPhone开发教程,iPhone开发基础教程PDF版

    iphone开发秘籍中文第2版--1 高清pdf版

    iphone开发秘籍中文第二版,pdf'高清版,好不容易找到的。欢迎下载

    4iPhone开发基础中文教程

    4iPhone开发基础中文教程4iPhone开发基础中文教程4iPhone开发基础中文教程4iPhone开发基础中文教程4iPhone开发基础中文教程

    深入浅出iPhone开发(清晰版,内含中英2个版本的书)

    知名的Head First系列丛书之一,风格与其他Head First系列一脉相承,一定能让读者轻松学会iPhone开发,《深入浅出iPhone开发》是针对iPhone开发的初学者设计的,以几个应用实例的开发为例,循序渐进地对iPhone开发的...

    iPhone应用开发技术专题

    本系统全称“电子渠道统一监控平台手机版”,是继多 媒体大屏系统之后又一比较炫的面向领导决策层的统一 监控平台。深受联通客户的好评。

    IPhone开发

    iphone开发秘籍,移动手机开发,参照软件开发应用

    iphone开发实战

    本书全面探讨了iPhone平台的两种编程方式——Web开发和SDK编程。全在Web开发方面,分别介绍了三个iPhone Web库,即WebKit、iUI和Canvas,并讨论了Web开发环境Dashcode,最后阐述Web应用程序的调试。在SDK开发方面,...

    Iphone开发系列源码——Image图片缩放随着手指

    Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image...

Global site tag (gtag.js) - Google Analytics