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

本文介绍了游戏开发中的几个实用技巧,包括使用随机数、在 UIImageView 中旋转图像、设置旋转点的方法、创建并存储 plist 文件,以及如何隐藏 NavigationBar。这些技巧对于游戏开发者来说非常有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 随机数的使用 头文件的引用

    #import <time> 
    #import <mach> 

   srandom()的使用 
  srandom((unsigned)(mach_absolute_time() &amp; 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 里的内容 while(tmp = [nse nextObject])
{ 
    NSString *stringBetweenBrackets = nil; 
    NSScanner *scanner = [NSScanner scannerWithString:tmp];
   [scanner scanUpToString:@"" ntoString:&amp;stringBetweenBrackets];
   NSLog([stringBetweenBrackets description]); 
}



 

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

 

 6 隐藏NavigationBar

 

[self.navigationController setNavigationBarHidden:YES animated:YES]; 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值